A self hosted chat application with end-to-end encrypted messaging.
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.

25 lines
1.3 KiB

  1. import log = require("loglevel");
  2. import { sprintf } from "sprintf-js";
  3. // import sprintf = require('sprintf-js').sprintf;
  4. export function fetchErrorHandler(response: Response) {
  5. // alertify.success('Current position : ' + alertify.get('notifier', 'position'));
  6. if (!response.ok) {
  7. return response.text().catch(err => {
  8. // the status was not ok and there is no json body
  9. // throw new Error(response.statusText);
  10. // window.alert(sprintf('Some error occured. Http code is %s', response.status));
  11. // alertify.error(sprintf('Some error occured. Http code is %s', response.status));
  12. log.error(sprintf('Some error occured. Http code is %s', response.status));
  13. log.error();
  14. return true;
  15. }).then(json => {
  16. // the status was not ok but there is a json body
  17. // throw new Error(json.error.message); // example error message returned by a REST API
  18. // window.alert(sprintf('Error: %s (Http code %s)', json, response.status));
  19. // alertify.error(sprintf('Some error occured. Http code is %s', response.status));
  20. log.error(sprintf('Some error occured. Http code is %s', response.status));
  21. log.error(json);
  22. return true;
  23. });
  24. }
  25. }