-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.ts
More file actions
34 lines (31 loc) · 1.03 KB
/
Copy patherrors.ts
File metadata and controls
34 lines (31 loc) · 1.03 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
// .klickd error definitions
// SPDX-License-Identifier: CC0-1.0
export type KlickdErrorCode =
| 'KLICKD_E_AUTH' // Wrong passphrase / GCM tag mismatch
| 'KLICKD_E_VERSION' // Unsupported klickd_version major
| 'KLICKD_E_FORMAT' // Malformed envelope JSON or missing fields
| 'KLICKD_E_KDF' // Unknown/unsupported KDF name
| 'KLICKD_E_WEAK_PASS' // Passphrase too short (< 8 chars)
| 'KLICKD_E_SCHEMA'; // Missing or invalid payload_schema_version
export class KlickdError extends Error {
constructor(
public readonly code: KlickdErrorCode,
message: string,
public readonly httpStatus?: number,
) {
super(`${code}: ${message}`);
this.name = 'KlickdError';
// Maintain proper stack trace in V8
if (Error.captureStackTrace) {
Error.captureStackTrace(this, KlickdError);
}
}
}
export const HTTP_STATUS: Record<KlickdErrorCode, number> = {
KLICKD_E_AUTH: 401,
KLICKD_E_VERSION: 400,
KLICKD_E_FORMAT: 400,
KLICKD_E_KDF: 400,
KLICKD_E_WEAK_PASS: 422,
KLICKD_E_SCHEMA: 400,
};