Suite of AT Protocol TypeScript libraries built on web standards
1/** Error thrown when a DID cannot be found.
2 * Could be due to a non-existent DID or network issues.
3 */
4export class DidNotFoundError extends Error {
5 constructor(public did: string) {
6 super(`Could not resolve DID: ${did}`);
7 }
8}
9
10/** Error thrown when DID resolution exceeds its configured timeout.
11 * @param ms Timeout in milliseconds.
12 */
13export class IdentityResolutionTimeoutError extends Error {
14 constructor(public ms: number, options?: ErrorOptions) {
15 super(`DID resolution timed out after ${ms}ms`, options);
16 }
17}
18
19/**
20 * Error thrown when a DID is not formatted correctly.
21 * Most commonly, a DID missing `did:` at the beginning
22 * or a DID missing a method.
23 */
24export class PoorlyFormattedDidError extends Error {
25 constructor(public did: string) {
26 super(`Poorly formatted DID: ${did}`);
27 }
28}
29
30/**
31 * Error thrown for unsupported methods.
32 * The methods supported are `did:plc` and `did:web`.
33 */
34export class UnsupportedDidMethodError extends Error {
35 constructor(public did: string) {
36 super(`Unsupported DID method: ${did}`);
37 }
38}
39
40/**
41 * Error thrown for DIDs where DID formatting could not be
42 * validated or parsed.
43 */
44export class PoorlyFormattedDidDocumentError extends Error {
45 constructor(
46 public did: string,
47 public doc: unknown,
48 ) {
49 super(`Poorly formatted DID Document: ${doc}`);
50 }
51}
52
53/**
54 * Error thrown for `did:web` DIDs where the path is not supported.
55 * Caused by more than one path segment.
56 */
57export class UnsupportedDidWebPathError extends Error {
58 constructor(public did: string) {
59 super(`Unsupported did:web paths: ${did}`);
60 }
61}