Move jsonWithDefault to a util
This commit is contained in:
parent
c474b1f652
commit
36fed0919d
|
@ -1,13 +1,9 @@
|
|||
import Service, { inject as service } from '@ember/service';
|
||||
import { computed } from '@ember/object';
|
||||
import { copy } from '@ember/object/internals';
|
||||
import PromiseObject from '../utils/classes/promise-object';
|
||||
import PromiseArray from '../utils/classes/promise-array';
|
||||
import { namespace } from '../adapters/application';
|
||||
|
||||
// When the request isn't ok (e.g., forbidden) handle gracefully
|
||||
const jsonWithDefault = defaultResponse => res =>
|
||||
res.ok ? res.json() : copy(defaultResponse, true);
|
||||
import jsonWithDefault from '../utils/json-with-default';
|
||||
|
||||
export default Service.extend({
|
||||
token: service(),
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import { copy } from '@ember/object/internals';
|
||||
|
||||
// Used with fetch.
|
||||
// Fetch only goes into the promise catch if there is a network error.
|
||||
// This means that handling a 4xx or 5xx error is the responsibility
|
||||
// of the developer.
|
||||
const jsonWithDefault = defaultResponse => res =>
|
||||
res.ok ? res.json() : copy(defaultResponse, true);
|
||||
|
||||
export default jsonWithDefault;
|
Loading…
Reference in New Issue