github.com/manicqin/nomad@v0.9.5/ui/app/utils/json-with-default.js (about)

     1  import { copy } from 'ember-copy';
     2  
     3  // Used with fetch.
     4  // Fetch only goes into the promise catch if there is a network error.
     5  // This means that handling a 4xx or 5xx error is the responsibility
     6  // of the developer.
     7  const jsonWithDefault = defaultResponse => res =>
     8    res.ok ? res.json() : copy(defaultResponse, true);
     9  
    10  export default jsonWithDefault;