/** * A class that represents a DWN Server error. */ export class DwnServerError extends Error { constructor( public code: string, message: string, ) { super(`${code}: ${message}`); this.name = 'DwnServerError'; } /** * Called by `JSON.stringify(...)` automatically. */ public toJSON(): { code: string, message: string } { return { code : this.code, message : this.message, }; } } /** * DWN Server error codes. */ export enum DwnServerErrorCode { ConnectionClosed = 'ConnectionClosed', ConnectionSubscriptionClosed = 'ConnectionSubscriptionClosed', ConnectionSubscriptionJsonRpcIdExists = 'ConnectionSubscriptionJsonRpcIdExists', ConnectionSubscriptionJsonRpcIdNotFound = 'ConnectionSubscriptionJsonRpcIdNotFound', ProofOfWorkInsufficientSolutionNonce = 'ProofOfWorkInsufficientSolutionNonce', ProofOfWorkInvalidOrExpiredChallenge = 'ProofOfWorkInvalidOrExpiredChallenge', ProofOfWorkManagerInvalidChallengeNonce = 'ProofOfWorkManagerInvalidChallengeNonce', ProofOfWorkManagerInvalidResponseNonceFormat = 'ProofOfWorkManagerInvalidResponseNonceFormat', ProofOfWorkManagerResponseNonceReused = 'ProofOfWorkManagerResponseNonceReused', ProviderAuthNotEnabled = 'ProviderAuthNotEnabled', ProviderAuthPluginLoadFailed = 'ProviderAuthPluginLoadFailed', ProviderAuthPluginNotConfigured = 'ProviderAuthPluginNotConfigured', ProviderAuthTokenInvalid = 'ProviderAuthTokenInvalid', RateLimitExceeded = 'RateLimitExceeded', RegistrationManagerInvalidOrOutdatedTermsOfServiceHash = 'RegistrationManagerInvalidOrOutdatedTermsOfServiceHash', RegistrationRequestMissingCredentials = 'RegistrationRequestMissingCredentials', TenantMessageQuotaExceeded = 'TenantMessageQuotaExceeded', TenantRegistrationOutdatedTermsOfService = 'TenantRegistrationOutdatedTermsOfService', TenantStorageQuotaExceeded = 'TenantStorageQuotaExceeded', TenantSuspended = 'TenantSuspended', }