Advertisement
Badal_hs_shah

CheckResponse

Jan 16th, 2023
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. interface CheckResponseProps {
  2.   res: any;
  3.   //successCodes?: Array<number>;
  4.   //errorCodes?: {[key: number]: (error: Error) => void};
  5.   delegate?: any;
  6. }
  7.  
  8. const checkResponse = ({
  9.   res,
  10.   //successCodes = [200, 201],
  11.   //errorCodes,
  12.   delegate,
  13. }: CheckResponseProps) => {
  14.   console.log('comes in check response loop');
  15.   console.log('*******RES ia ', res);
  16.   let successCodes = [200, 201];
  17.   if (successCodes.includes(res.status)) {
  18.     console.log('here is success block');
  19.     return res;
  20.   } else {
  21.     // if (errorCodes && errorCodes[res.status]) {
  22.     //   console.log('here is errorcode block');
  23.     //   handleError(
  24.     //     errorCodes[res.status](new APIError(res.status, res.message)),
  25.     //   );
  26.     // } else {
  27.     delegate = res;
  28.     console.log('here is else  block');
  29.     handleError({error: new APIError(res.status, res.message), delegate});
  30.     //}
  31.   }
  32. };
  33.  
  34. export default checkResponse;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement