github.com/hernad/nomad@v1.6.112/ui/app/utils/json-with-default.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { copy } from 'ember-copy'; 7 8 // Used with fetch. 9 // Fetch only goes into the promise catch if there is a network error. 10 // This means that handling a 4xx or 5xx error is the responsibility 11 // of the developer. 12 const jsonWithDefault = (defaultResponse) => (res) => 13 res.ok ? res.json() : copy(defaultResponse, true); 14 15 export default jsonWithDefault;