-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.tsx
More file actions
85 lines (78 loc) · 2.36 KB
/
error.tsx
File metadata and controls
85 lines (78 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import type { Middleware } from "@reduxjs/toolkit";
import { isRejectedWithValue } from "@reduxjs/toolkit";
import * as Sentry from "sentry-expo";
import ApiDebugToastExpand from "../components/ApiDebugToastExpand";
import { showToast } from "../utils/toast";
type IgnoreError = {
endpointName?: string;
status?: string;
};
const ignoreErrors: IgnoreError[] = [
{
status: "403",
},
{
endpointName: "checkUsername",
status: "400",
},
{
status: "426",
},
];
export class RTKQueryError extends Error {
constructor(message?: string, endpointName?: string, status?: string) {
super(message);
this.name = `RTKQ: ${endpointName} | ${status}`;
this.cause = message;
}
}
export const rtkQueryErrorLogger: Middleware = () => (next) => (action) => {
if (isRejectedWithValue(action)) {
const type: string | undefined = action?.type;
const status: string | undefined = action?.payload?.status?.toString();
const message: string | undefined = action?.payload?.data?.message;
const endpointName: string | undefined = action?.meta?.arg?.endpointName;
const fullAction = JSON.stringify(action);
// ignore errors
if (
ignoreErrors.some(
(ignoreError) =>
(ignoreError.endpointName === endpointName || !ignoreError.endpointName) &&
(ignoreError.status === status || !ignoreError.status)
)
) {
return next(action);
}
Sentry.Native.withScope((scope) => {
scope.setExtra("type", type);
scope.setExtra("status", status);
scope.setExtra("endpointName", endpointName);
scope.setExtra("fullAction", fullAction);
Sentry.Native.captureException(new RTKQueryError(message, endpointName, status));
});
const expandable = ["development", "preview", "staging"].includes(
process.env.EXPO_PUBLIC_EAS_PROFILE ?? ""
);
const toastHandler = showToast(
{
variant: "error",
message: "Oops! Something went wrong...",
expandable,
ExpandableComponent: (
<ApiDebugToastExpand
type={type}
endpoint={endpointName}
status={status}
message={message}
fullAction={JSON.stringify(action)}
onDismiss={() => toastHandler.destroy()}
/>
),
},
{
autoDismiss: !expandable,
}
);
}
return next(action);
};