Secure storage and distribution of cryptographic keys in ATProto applications
1/**
2 * Base error class for all keyserver-related errors
3 */
4export class KeyserverError extends Error {
5 public readonly statusCode?: number
6
7 constructor(message: string, statusCode?: number) {
8 super(message)
9 this.name = 'KeyserverError'
10 this.statusCode = statusCode
11 Object.setPrototypeOf(this, KeyserverError.prototype)
12 }
13}
14
15/**
16 * Thrown when authentication fails (401 Unauthorized)
17 */
18export class UnauthorizedError extends KeyserverError {
19 constructor(message: string = 'Authentication required') {
20 super(message, 401)
21 this.name = 'UnauthorizedError'
22 Object.setPrototypeOf(this, UnauthorizedError.prototype)
23 }
24}
25
26/**
27 * Thrown when access is denied (403 Forbidden)
28 */
29export class ForbiddenError extends KeyserverError {
30 constructor(message: string = 'Access denied') {
31 super(message, 403)
32 this.name = 'ForbiddenError'
33 Object.setPrototypeOf(this, ForbiddenError.prototype)
34 }
35}
36
37/**
38 * Thrown when a resource is not found (404 Not Found)
39 */
40export class NotFoundError extends KeyserverError {
41 constructor(message: string = 'Resource not found') {
42 super(message, 404)
43 this.name = 'NotFoundError'
44 Object.setPrototypeOf(this, NotFoundError.prototype)
45 }
46}
47
48/**
49 * Thrown for network errors (5xx status codes, timeouts, etc.)
50 */
51export class NetworkError extends KeyserverError {
52 constructor(message: string = 'Network error occurred', statusCode?: number) {
53 super(message, statusCode)
54 this.name = 'NetworkError'
55 Object.setPrototypeOf(this, NetworkError.prototype)
56 }
57}
58
59/**
60 * Thrown when decryption fails
61 */
62export class DecryptionError extends Error {
63 constructor(message: string = 'Failed to decrypt message') {
64 super(message)
65 this.name = 'DecryptionError'
66 Object.setPrototypeOf(this, DecryptionError.prototype)
67 }
68}