Skip to content

Commit

Permalink
chore: define the exception name explicitly (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
3846masa authored Aug 19, 2024
1 parent d1b2205 commit 78eb60c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/BKTExceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import {
} from './internal/model/MetricsEventData'

abstract class BKTBaseException extends Error {
name = 'BKTBaseException'
type?: ErrorMetricsEventType = undefined
constructor(msg?: string) {
super(msg)
this.name = new.target.name
Object.setPrototypeOf(this, new.target.prototype)
}
}

// server redirect 300..399
export class RedirectRequestException extends BKTBaseException {
name = 'RedirectRequestException' as const
type?: ErrorMetricsEventType = MetricsEventType.RedirectRequestError
statusCode: number

Expand All @@ -26,43 +27,53 @@ export class RedirectRequestException extends BKTBaseException {
// server errors ---
// 400: Bad Request
export class BadRequestException extends BKTBaseException {
name = 'BadRequestException' as const
type?: ErrorMetricsEventType = MetricsEventType.BadRequestError
}
// 401: Unauthorized
export class UnauthorizedException extends BKTBaseException {
name = 'UnauthorizedException' as const
type?: ErrorMetricsEventType = MetricsEventType.UnauthorizedError
}
// 403: Forbidden
export class ForbiddenException extends BKTBaseException {
name = 'ForbiddenException' as const
type?: ErrorMetricsEventType = MetricsEventType.ForbiddenError
}
// 404: NotFound
export class NotFoundException extends BKTBaseException {
name = 'NotFoundException' as const
type?: ErrorMetricsEventType = MetricsEventType.NotFoundError
}
// 405: InvalidHttpMethod
export class InvalidHttpMethodException extends BKTBaseException {
name = 'InvalidHttpMethodException' as const
type?: ErrorMetricsEventType = MetricsEventType.InternalSdkError
}
// 413: Payload Too Large
export class PayloadTooLargeException extends BKTBaseException {
name = 'PayloadTooLargeException' as const
type?: ErrorMetricsEventType = MetricsEventType.PayloadTooLargeError
}
// 499: Client Closed Request
export class ClientClosedRequestException extends BKTBaseException {
name = 'ClientClosedRequestException' as const
type?: ErrorMetricsEventType = MetricsEventType.ClientClosedRequestError
}
// 500: Internal Server Error
export class InternalServerErrorException extends BKTBaseException {
name = 'InternalServerErrorException' as const
type?: ErrorMetricsEventType = MetricsEventType.InternalServerError
}
// 502, 503, 504: Service Unavailable
export class ServiceUnavailableException extends BKTBaseException {
name = 'ServiceUnavailableException' as const
type?: ErrorMetricsEventType = MetricsEventType.ServiceUnavailableError
}

// network errors
export class TimeoutException extends BKTBaseException {
name = 'TimeoutException' as const
type?: ErrorMetricsEventType = MetricsEventType.TimeoutError
timeoutMillis: number

Expand All @@ -72,15 +83,21 @@ export class TimeoutException extends BKTBaseException {
}
}
export class NetworkException extends BKTBaseException {
name = 'NetworkException' as const
type?: ErrorMetricsEventType = MetricsEventType.NetworkError
}

// sdk errors
export class IllegalArgumentException extends BKTBaseException {}
export class IllegalStateException extends BKTBaseException {}
export class IllegalArgumentException extends BKTBaseException {
name = 'IllegalArgumentException' as const
}
export class IllegalStateException extends BKTBaseException {
name = 'IllegalStateException' as const
}

// unknown errors
export class UnknownException extends BKTBaseException {
name = 'UnknownException' as const
type?: ErrorMetricsEventType = MetricsEventType.UnknownError
statusCode?: number

Expand Down

0 comments on commit 78eb60c

Please sign in to comment.