Fix incident error handling (#4185)
# What this PR does
Throw full fetch response to allow existing error handlers to work
properly
## Checklist
- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
show up in the autogenerated release notes.
This commit is contained in:
parent
4ac2df19b5
commit
42024a9ab3
3 changed files with 10 additions and 10 deletions
|
|
@ -4,7 +4,7 @@ export function initErrorDataState(): Partial<PageErrorData> {
|
|||
return { isUnknownError: false, isWrongTeamError: false, wrongTeamNoPermissions: false };
|
||||
}
|
||||
|
||||
export function getWrongTeamResponseInfo({ response }): Partial<PageErrorData> {
|
||||
export function getWrongTeamResponseInfo(response): Partial<PageErrorData> {
|
||||
if (response) {
|
||||
if (response.status === 404) {
|
||||
return { isNotFoundError: true };
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ const REQUEST_CONFIG = {
|
|||
};
|
||||
const URL = 'https://someurl.com';
|
||||
const SUCCESSFUL_RESPONSE_MOCK = { ok: true };
|
||||
const ERROR_MOCK = 'error';
|
||||
const FAILING_RESPONSE_MOCK = { ok: false, json: () => 'ERROR' };
|
||||
const customFetch = getCustomFetchFn({ withGlobalErrorHandler: true });
|
||||
|
||||
describe('customFetch', () => {
|
||||
|
|
@ -53,10 +53,10 @@ describe('customFetch', () => {
|
|||
describe('if response is not successful', () => {
|
||||
it('should push event and error to faro', async () => {
|
||||
(FaroHelper.faro.api.getOTEL as unknown as jest.Mock).mockReturnValueOnce(undefined);
|
||||
fetchMock.mockResolvedValueOnce({ ok: false, json: () => ERROR_MOCK });
|
||||
await expect(customFetch(URL, REQUEST_CONFIG)).rejects.toEqual(ERROR_MOCK);
|
||||
fetchMock.mockResolvedValueOnce(FAILING_RESPONSE_MOCK);
|
||||
await expect(customFetch(URL, REQUEST_CONFIG)).rejects.toEqual(FAILING_RESPONSE_MOCK);
|
||||
expect(FaroHelper.faro.api.pushEvent).toHaveBeenCalledWith('Request failed', { url: URL });
|
||||
expect(FaroHelper.faro.api.pushError).toHaveBeenCalledWith(ERROR_MOCK);
|
||||
expect(FaroHelper.faro.api.pushError).toHaveBeenCalledWith(FAILING_RESPONSE_MOCK.json());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -108,10 +108,10 @@ describe('customFetch', () => {
|
|||
|
||||
describe('if response is not successful', () => {
|
||||
it('should reject Promise, push event to faro, set span status to error and end span', async () => {
|
||||
fetchMock.mockResolvedValueOnce({ ok: false, json: () => ERROR_MOCK });
|
||||
await expect(customFetch(URL, REQUEST_CONFIG)).rejects.toEqual(ERROR_MOCK);
|
||||
fetchMock.mockResolvedValueOnce(FAILING_RESPONSE_MOCK);
|
||||
await expect(customFetch(URL, REQUEST_CONFIG)).rejects.toEqual(FAILING_RESPONSE_MOCK);
|
||||
expect(FaroHelper.faro.api.pushEvent).toHaveBeenCalledWith('Request failed', { url: URL });
|
||||
expect(FaroHelper.faro.api.pushError).toHaveBeenCalledWith(ERROR_MOCK);
|
||||
expect(FaroHelper.faro.api.pushError).toHaveBeenCalledWith(FAILING_RESPONSE_MOCK.json());
|
||||
expect(spanEndMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ export const getCustomFetchFn =
|
|||
if (withGlobalErrorHandler) {
|
||||
showApiError(res);
|
||||
}
|
||||
reject(errorData);
|
||||
reject(res);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -78,7 +78,7 @@ export const getCustomFetchFn =
|
|||
if (withGlobalErrorHandler) {
|
||||
showApiError(res);
|
||||
}
|
||||
throw errorData;
|
||||
throw res;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue