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.

41 lines
1.5 KiB

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