Open Bug 1473777 Opened 7 years ago Updated 3 years ago

use getData function in lieu of fetch directly (where possible)

Categories

(Tree Management :: Treeherder: Frontend, defect, P3)

defect

Tracking

(Not tracked)

People

(Reporter: camd, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

Fix error handling in places where were our calls have switched to using fetch. When using $http, you would check for errors by having something like this: $http.get(url).then((success) => { ... }, (error) => { ... }); But with fetch, you don't use the second callback, you check the response for ``.ok`` like: fetch.get(url).then((resp) => { if (resp.ok) { // success } else { // fail, throw an exception... } }).catch(error => alert somehow...) The catch gets hit directly only when you have connectivity issues and a few other circumstances. 400 and 500 response codes still go to the first call in the .then.
Assignee: nobody → cdawson
Status: NEW → ASSIGNED
Priority: -- → P2
Attachment #8990419 - Flags: review?(emorley)
Blocks: 1473571
Attachment #8990419 - Flags: review?(emorley) → review+
Blocks: 1450039
As part of working on this, it would be good to special-case HTTP 503s and ensure that the error message shown to the user says "Request exceeded maximum API time limit" or something along those lines - since the default Heroku page content says "app unavailable" which is misleading. Perhaps an helper wrapper for all fetch calls would be useful?
Blocks: 1504990
Summary: When using fetch, must check response.ok for errors → When using fetch, must check response.ok for errors (and special-case HTTP 503)
As part of the perfherder conversion I moved the `getData` method (designed to return error messages in json responses or plain text) from IFV's helpers into the general `helpers/http.js` file. export const getData = async function getData(url) { let failureStatus = null; const response = await fetch(url); if (!response.ok) { failureStatus = response.status; } if (response.headers.get('content-type') === 'text/html' && failureStatus) { return { data: { [failureStatus]: response.statusText }, failureStatus }; } const data = await response.json(); return { data, failureStatus }; }; But, for the case of the 503's I noticed IFV doesn't show the special message I programmed for this type of error (in a separate helper function) because it seems Heroku by default returns the "app unavailable" page unless we set a customized page to be returned instead: https://devcenter.heroku.com/articles/error-pages.
Summary: When using fetch, must check response.ok for errors (and special-case HTTP 503) → use getData function in lieu of fetch directly (where possible)
No longer blocks: treeherder-react

PushModel.getList is being updated via bug 1527824.

Blocks: 1067846
No longer blocks: 1504990
Assignee: cdawson → nobody
Status: ASSIGNED → NEW
Priority: P2 → P3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: