-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathcreateFeedbackError.ts
More file actions
24 lines (21 loc) · 842 Bytes
/
createFeedbackError.ts
File metadata and controls
24 lines (21 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import type { FeedbackErrorCode, FeedbackErrorMessages } from '@sentry/core';
import {
ERROR_EMPTY_MESSAGE_TEXT,
ERROR_FORBIDDEN_TEXT,
ERROR_GENERIC_TEXT,
ERROR_NO_CLIENT_TEXT,
ERROR_TIMEOUT_TEXT,
} from '../constants';
const DEFAULT_MESSAGES: Record<FeedbackErrorCode, string> = {
ERROR_EMPTY_MESSAGE: ERROR_EMPTY_MESSAGE_TEXT,
ERROR_NO_CLIENT: ERROR_NO_CLIENT_TEXT,
ERROR_TIMEOUT: ERROR_TIMEOUT_TEXT,
ERROR_FORBIDDEN: ERROR_FORBIDDEN_TEXT,
ERROR_GENERIC: ERROR_GENERIC_TEXT,
};
export function resolveFeedbackErrorMessage(code: FeedbackErrorCode, messages?: FeedbackErrorMessages): string {
return messages?.[code] ?? DEFAULT_MESSAGES[code];
}
export function createFeedbackError(code: FeedbackErrorCode, messages?: FeedbackErrorMessages): Error {
return new Error(resolveFeedbackErrorMessage(code, messages));
}