@omneedia/auth-js
Version:
Isomorphic Auth client
98 lines (82 loc) • 2.26 kB
text/typescript
export class AuthError extends Error {
protected __isAuthError = true
constructor(message: string) {
super(message)
this.name = 'AuthError'
}
}
export function isAuthError(error: unknown): error is AuthError {
return typeof error === 'object' && error !== null && '__isAuthError' in error
}
export class AuthApiError extends AuthError {
status: number
constructor(message: string, status: number) {
super(message)
this.name = 'AuthApiError'
this.status = status
}
toJSON() {
return {
name: this.name,
message: this.message,
status: this.status,
}
}
}
export function isAuthApiError(error: unknown): error is AuthApiError {
return isAuthError(error) && error.name === 'AuthApiError'
}
export class AuthUnknownError extends AuthError {
originalError: unknown
constructor(message: string, originalError: unknown) {
super(message)
this.name = 'AuthUnknownError'
this.originalError = originalError
}
}
export class CustomAuthError extends AuthError {
name: string
status: number
constructor(message: string, name: string, status: number) {
super(message)
this.name = name
this.status = status
}
toJSON() {
return {
name: this.name,
message: this.message,
status: this.status,
}
}
}
export class AuthSessionMissingError extends CustomAuthError {
constructor() {
super('Auth session missing!', 'AuthSessionMissingError', 400)
}
}
export class AuthInvalidCredentialsError extends CustomAuthError {
constructor(message: string) {
super(message, 'AuthInvalidCredentialsError', 400)
}
}
export class AuthImplicitGrantRedirectError extends CustomAuthError {
details: { error: string; code: string } | null = null
constructor(message: string, details: { error: string; code: string } | null = null) {
super(message, 'AuthImplicitGrantRedirectError', 500)
this.details = details
}
toJSON() {
return {
name: this.name,
message: this.message,
status: this.status,
details: this.details,
}
}
}
export class AuthRetryableFetchError extends CustomAuthError {
constructor(message: string, status: number) {
super(message, 'AuthRetryableFetchError', status)
}
}