You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1.3 KiB
26 lines
1.3 KiB
import log = require("loglevel");
|
|
import { sprintf } from "sprintf-js";
|
|
// import sprintf = require('sprintf-js').sprintf;
|
|
|
|
export function fetchErrorHandler(response: Response) {
|
|
// alertify.success('Current position : ' + alertify.get('notifier', 'position'));
|
|
if (!response.ok) {
|
|
return response.text().catch(err => {
|
|
// the status was not ok and there is no json body
|
|
// throw new Error(response.statusText);
|
|
// window.alert(sprintf('Some error occured. Http code is %s', response.status));
|
|
// alertify.error(sprintf('Some error occured. Http code is %s', response.status));
|
|
log.error(sprintf('Some error occured. Http code is %s', response.status));
|
|
log.error();
|
|
return true;
|
|
}).then(json => {
|
|
// the status was not ok but there is a json body
|
|
// throw new Error(json.error.message); // example error message returned by a REST API
|
|
// window.alert(sprintf('Error: %s (Http code %s)', json, response.status));
|
|
// alertify.error(sprintf('Some error occured. Http code is %s', response.status));
|
|
log.error(sprintf('Some error occured. Http code is %s', response.status));
|
|
log.error(json);
|
|
return true;
|
|
});
|
|
}
|
|
}
|