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.

29 lines
1.4 KiB

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