helper.js 567B

1234567891011121314151617181920212223
  1. export const libHandleFetchResult = async fetchResult => {
  2. switch (fetchResult.status) {
  3. case 200:
  4. case 304:
  5. const resultJson = await fetchResult.clone().json()
  6. return new Promise((resolve, reject) => resolve({
  7. apiResponse: fetchResult,
  8. body: resultJson
  9. }))
  10. case 204:
  11. return fetchResult
  12. case 400:
  13. case 404:
  14. case 409:
  15. case 500:
  16. case 501:
  17. case 502:
  18. case 503:
  19. case 504:
  20. return new Promise((resolve, reject) => reject(fetchResult)) // @TODO : handle errors from api result
  21. }
  22. }