forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseError.ts
More file actions
44 lines (41 loc) · 1.27 KB
/
Copy pathparseError.ts
File metadata and controls
44 lines (41 loc) · 1.27 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
import type { ClerkAPIError as ClerkAPIErrorInterface, ClerkAPIErrorJSON } from '../types';
import { ClerkAPIError } from './clerkApiError';
/**
* Parses an array of ClerkAPIErrorJSON objects into an array of ClerkAPIError objects.
*
* @internal
*/
export function parseErrors(data: ClerkAPIErrorJSON[] = []): ClerkAPIErrorInterface[] {
return data.length > 0 ? data.map(e => new ClerkAPIError(e)) : [];
}
/**
* Parses a ClerkAPIErrorJSON object into a ClerkAPIError object.
*
* @deprecated Use `ClerkAPIError` class instead
*
* @internal
*/
export function parseError(error: ClerkAPIErrorJSON): ClerkAPIErrorInterface {
return new ClerkAPIError(error);
}
/**
* Converts a ClerkAPIError object into a ClerkAPIErrorJSON object.
*
* @internal
*/
export function errorToJSON(error: ClerkAPIError | null): ClerkAPIErrorJSON {
return {
code: error?.code || '',
message: error?.message || '',
long_message: error?.longMessage,
meta: {
param_name: error?.meta?.paramName,
session_id: error?.meta?.sessionId,
email_addresses: error?.meta?.emailAddresses,
identifiers: error?.meta?.identifiers,
zxcvbn: error?.meta?.zxcvbn,
plan: error?.meta?.plan,
is_plan_upgrade_possible: error?.meta?.isPlanUpgradePossible,
},
};
}