-
Notifications
You must be signed in to change notification settings - Fork 10
[risk=no][RW-8242] Use fetchWithErrorModal() for workspace-about API calls #7082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
.catch((error) => { | ||
console.error(error); | ||
}); | ||
fetchWithErrorModal(() => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the simplest way to use the new fetchWithErrorModal
: a default popup will appear with info if there's an error. See errors and errors.spec for more examples
() => '' | ||
); | ||
|
||
return `An API error${errorCodeStr} occurred${detailsStr}${messageStr}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See errors.spec for examples of how the final result looks
e8656db
to
57df2e4
Compare
errorCode && errorCode !== ErrorCode.PARSEERROR | ||
? ` of type ${errorCode.toString()}` | ||
: ''; | ||
const messageStr = message ? `: ${message}` : '.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Encode message to remove HTML escaping?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an example of where this would be necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I create a corhort/dataset/something else with ‘<’, ‘>’, ‘alert’. inside.
Would that lead to XSS attack if we want to prin balbla not found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Text in React components is escaped under all but the most unusual circumstances.
fetchWithErrorModal(() => | ||
profileApi().updatePageVisits({ page: pageId }) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably return the promises for these so the caller can make the decision about whether it makes sense to await them.
fetchWithErrorModal(() => | |
profileApi().updatePageVisits({ page: pageId }) | |
); | |
return fetchWithErrorModal(() => | |
profileApi().updatePageVisits({ page: pageId }) | |
); |
errorCode && errorCode !== ErrorCode.PARSEERROR | ||
? ` of type ${errorCode.toString()}` | ||
: ''; | ||
const messageStr = message ? `: ${message}` : '.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Text in React components is escaped under all but the most unusual circumstances.
ui/src/app/utils/errors.tsx
Outdated
* await responseP.then(resp => | ||
* errorHandlerWithFallback( | ||
* resp, | ||
* (er) => er.statusCode === 404, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: err
is more idiomatic for an error variable name.
ui/src/app/utils/errors.tsx
Outdated
return apiCall() | ||
.then(onSuccess) | ||
.catch(async (apiError) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return apiCall() | |
.then(onSuccess) | |
.catch(async (apiError) => { | |
return apiCall() | |
.catch(async (apiError) => { |
ui/src/app/utils/errors.tsx
Outdated
expectedResponseMatcher?: (ErrorResponse) => boolean, | ||
customErrorResponseFormatter?: (ErrorResponse) => NotificationStore | ||
): Promise<NotificationStore> => | ||
convertAPIError(anyApiErrorResponse).then((errorResponse) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function (convertAPIError
) perhaps should be avoided. It takes an ErrorResponse, calls .json()
on it, and then throws it away if that method fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a new version of this is toApiErrorResponse()
which retains all fields in the original and the json()
TEMP JOEL HACK force 404 in getFirecloudWorkspaceUserRoles() callWithFallbackErrorModal pocErrorHandler
57df2e4
to
3d53b85
Compare
this.loadUserRoles(workspace); | ||
} | ||
|
||
async loadInitialCreditsUsage(workspace: WorkspaceData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to await these, so they don't need to be async
Add a new
fetchWithErrorModal()
function which wraps API calls, and use this function for allworkspace-about
API calls.By default, it pops up an error modal when the API returns an error (like 404). It takes an optional options object with the following parameters:
onDismiss
handlerThe error modal behavior is powered by the existing
notificationStore
/NotificationModal
An example of the default handler

A custom handler which is only applied for 404 (otherwise the default is used)
PR checklist