This package has been deprecated

Author message:

Please use ember-test-helper's setupOnerror instead

@zestia/ember-error-handling

1.1.8 • Public • Published

@zestia/ember-error-handling

The Ember guides suggest using Ember.onerror to handle errors and Ember.RSVP.on('error') to handle uncaught promise rejections. More often than not, you want to use the same handler for both these scenarios.

This Ember addon amalgamates the two hooks into a single top level error handler for your application.

It also allows specific errors to be squelched (ignored completely), which is paricularly useful when testing error scenarios.

Note If you are using await (native promises), rather than RSVP, and you still wish to have the ability to squelch errors - you must still wrap the chain with RSVP.resolve.

Installation

ember install @zestia/ember-error-handling
ember generate instance-initializer error-handling

Setup

// app/instance-initializers/error-handling.js

export function initialize(appInstance) {
  const errorHandlingService = appInstance.lookup('service:error-handling');

  errorHandlingService.onerror = (error) => {
    // Here is a good place to send the error to a third party.
  };

  errorHandlingService.squelch((error) => {
    // Return true to squelch
  });
}

export default {
  name: 'error-handling',
  initialize,
};

Example

test('something', async function (assert) {
  assert.expect(1);

  errorHandlingService.squelch((error) => {
    // Squelch can be called multiple times
  });
});

Package Sidebar

Install

npm i @zestia/ember-error-handling

Weekly Downloads

10

Version

1.1.8

License

MIT

Unpacked Size

8.27 kB

Total Files

13

Last publish

Collaborators

  • philliphaines
  • amk221