errorHandling.ts 369 B

123456789101112131415161718
  1. import { ServerResponse } from 'redux/interfaces';
  2. export const getResponse = async (
  3. response: Response
  4. ): Promise<ServerResponse> => {
  5. let body;
  6. try {
  7. body = await response.json();
  8. } catch (e) {
  9. // do nothing;
  10. }
  11. return {
  12. status: response.status,
  13. statusText: response.statusText,
  14. url: response.url,
  15. message: body?.message,
  16. };
  17. };