Sha256: 11a8be1b319d9df23f9140613173d15847edfc4d430c826466f8fab1b3c04276

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

import * as RSVP from 'rsvp';
import { backburner, _rsvpErrorQueue } from '@ember/runloop';
import { getDispatchOverride } from 'ember-error-handling';
import { assert } from '@ember/debug';

RSVP.configure('async', (callback, promise) => {
  backburner.schedule('actions', null, callback, promise);
});

RSVP.configure('after', cb => {
  backburner.schedule(_rsvpErrorQueue, null, cb);
});

RSVP.on('error', onerrorDefault);

export function onerrorDefault(reason) {
  let error = errorFor(reason);
  if (error) {
    let overrideDispatch = getDispatchOverride();
    if (overrideDispatch) {
      overrideDispatch(error);
    } else {
      throw error;
    }
  }
}

function errorFor(reason) {
  if (!reason) return;

  if (reason.errorThrown) {
    return unwrapErrorThrown(reason);
  }

  if (reason.name === 'UnrecognizedURLError') {
    assert(`The URL '${reason.message}' did not match any routes in your application`, false);
    return;
  }

  if (reason.name === 'TransitionAborted') {
    return;
  }

  return reason;
}

function unwrapErrorThrown(reason) {
  let error = reason.errorThrown;
  if (typeof error === 'string') {
    error = new Error(error);
  }
  Object.defineProperty(error, '__reason_with_error_thrown__', {
    value: reason,
    enumerable: false,
  });
  return error;
}

export default RSVP;

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
discourse-ember-source-3.5.1.1 dist/es/ember-runtime/lib/ext/rsvp.js
discourse-ember-source-3.5.1.0 dist/dist/es/ember-runtime/lib/ext/rsvp.js