UNPKG

@atproto/did

Version:

DID resolution and verification library

38 lines 1.25 kB
export class DidError extends Error { constructor(did, message, code, status = 400, cause) { super(message, { cause }); this.did = did; this.code = code; this.status = status; } /** * For compatibility with error handlers in common HTTP frameworks. */ get statusCode() { return this.status; } toString() { return `${this.constructor.name} ${this.code} (${this.did}): ${this.message}`; } static from(cause, did) { if (cause instanceof DidError) { return cause; } const message = cause instanceof Error ? cause.message : typeof cause === 'string' ? cause : 'An unknown error occurred'; const status = (typeof cause?.['statusCode'] === 'number' ? cause['statusCode'] : undefined) ?? (typeof cause?.['status'] === 'number' ? cause['status'] : undefined); return new DidError(did, message, 'did-unknown-error', status, cause); } } export class InvalidDidError extends DidError { constructor(did, message, cause) { super(did, message, 'did-invalid', 400, cause); } } //# sourceMappingURL=did-error.js.map