2019-03-26 04:55:06 +00:00
|
|
|
import { copy } from 'ember-copy';
|
2018-11-02 05:07:58 +00:00
|
|
|
|
|
|
|
// 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.
|
2021-12-28 14:45:20 +00:00
|
|
|
const jsonWithDefault = (defaultResponse) => (res) =>
|
2018-11-02 05:07:58 +00:00
|
|
|
res.ok ? res.json() : copy(defaultResponse, true);
|
|
|
|
|
|
|
|
export default jsonWithDefault;
|