Skip to content
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

Remove loggedErrors reducer/saga #726

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions premiser-ui/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,3 @@ export const autocompletes = {
(suggestionsKey: SuggestionsKey) => ({ suggestionsKey })
),
};

export const errors = {
logError: createAction("ERRORS/LOG_ERROR", ({ error }: { error: Error }) => ({
error,
})),
clearLoggedErrors: createAction("ERRORS/CLEAR_LOGGED_ERRORS"),
};
4 changes: 2 additions & 2 deletions premiser-ui/src/apiActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ import { SuggestionsKey, WidgetId } from "./types";
import { HttpStatusCode } from "axios";
import { TagPropositionVote } from "./viewModels";

// TODO(113) type response.error as an Error when we remove redux-actions conventions
// TODO(#113) type response.error as an Error when we remove redux-actions conventions
export type ApiActionCreator<
Args extends any[],
Route extends ServiceRoute,
Expand Down Expand Up @@ -1607,7 +1607,7 @@ export const api = {
url,
quotation,
},
// TODO(482) remove normalizationSchema once we can figure out how to type it.
// TODO(#482) remove normalizationSchema once we can figure out how to type it.
normalizationSchema: { mediaExcerptInfo: nullSchema },
})
),
Expand Down
25 changes: 0 additions & 25 deletions premiser-ui/src/reducers/errors.ts

This file was deleted.

2 changes: 0 additions & 2 deletions premiser-ui/src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import auth from "./auth";
import autocompletes from "./autocompletes";
import editors from "./editors";
import entities from "./entities";
import errors from "./errors";
import privacyConsent from "./privacyConsent";

const widgets = combineReducers({
Expand All @@ -46,7 +45,6 @@ export default (history: History) =>
createAppearancePage,
editors,
entities,
errors,
explorePage,
factCheckPage,
justificationsPage,
Expand Down
19 changes: 18 additions & 1 deletion premiser-ui/src/sagas/apiSagas.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { put, call, select } from "typed-redux-saga";
import cloneDeep from "lodash/cloneDeep";
import isEmpty from "lodash/isEmpty";
import { isEmpty, pick } from "lodash";

import { FetchHeaders, RequestOptions, sendRequest } from "../api";
import { selectAuthToken } from "../selectors";
import { callApiResponse } from "../apiActions";
import { tryWaitOnRehydrate } from "./appSagas";
import { pageLoadId, getSessionStorageId } from "../identifiers";
import * as customHeaderKeys from "../customHeaderKeys";
import { logger } from "../logger";

export type FetchInit = Omit<RequestOptions, "endpoint">;

Expand All @@ -28,11 +29,27 @@ export function* callApi(
const responseAction = callApiResponse(responseData);
return yield* put(responseAction);
} catch (error) {
logApiError(error, endpoint);
const responseAction = callApiResponse(error);
return yield* put(responseAction);
}
}

function logApiError(error: unknown, endpoint: string) {
if (!(error instanceof Error)) {
logger.warn(
`logApiError called with non-Error object. Type: ${typeof error}`
);
return;
}
const identifierKeys = pick(error, customHeaderKeys.identifierKeys);
const options = { extra: { endpoint } };
if (!isEmpty(identifierKeys)) {
options.extra = { ...options.extra, ...identifierKeys };
}
logger.exception(error, options);
}

function* constructHeaders(fetchInit: FetchInit) {
const headersUpdate = {} as FetchHeaders;
// Add auth token to all API requests
Expand Down
2 changes: 0 additions & 2 deletions premiser-ui/src/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
redirectToLoginWhenUnauthenticated,
redirectUnauthenticatedUserToLoginOnPagesNeedingAuthentication,
} from "./flowSagas";
import { logErrors } from "./logErrorsSaga";
import { cancelResourceApiCalls, resourceApiCalls } from "./resourceApiSagas";

export default () =>
Expand All @@ -56,7 +55,6 @@ export default () =>
checkAuthExpirationOnRehydrate(),
checkAuthExpirationPeriodically(),
checkAuthExpiration(),
logErrors(),

configureAfterLogin(),
configureAfterRehydrate(),
Expand Down
43 changes: 0 additions & 43 deletions premiser-ui/src/sagas/logErrorsSaga.ts

This file was deleted.

2 changes: 0 additions & 2 deletions premiser-ui/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export const selectUserExternalIds = (
state: RootState,
defaultValue: Partial<UserExternalIds>
) => state.auth.user?.externalIds || defaultValue;
export const selectLoggedErrors = (state: RootState) =>
state.errors.loggedErrors;
export const selectIsWindowNarrow = (state: RootState) =>
state.app.isWindowNarrow;
export const selectAuthToken = (state: RootState) => state.auth.authToken;
Expand Down
4 changes: 1 addition & 3 deletions premiser-ui/src/setupStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ export const setupStore = (
// The normalization schemas are convenient to have, but non-serializable. We could also
// include a string identifier/descriptor of the normalization schema and look it up
// when we need it.
// TODO(154) remove these ignores
// TODO(#154) remove these ignores
"payload.normalizationSchema",
"meta.normalizationSchema",
"payload.itemFactory",
// TODO(472) remove once we remove error-logging Saga.
"errors.loggedErrors",
/payload\.apiAction\.payload\.normalizationSchema\.*/,
/payload\.meta\.normalizationSchema\.[^.]+/,
"payload.mediaExcerpt.created",
Expand Down
Loading