Skip to content

Commit 33f7334

Browse files
authored
improv(event-handler): rename ServiceError class to HttpError (#4610)
1 parent eedaf70 commit 33f7334

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

packages/event-handler/src/rest/Router.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import {
3131
} from './converters.js';
3232
import { ErrorHandlerRegistry } from './ErrorHandlerRegistry.js';
3333
import {
34+
HttpError,
3435
InternalServerError,
3536
MethodNotAllowedError,
3637
NotFoundError,
37-
ServiceError,
3838
} from './errors.js';
3939
import { Route } from './Route.js';
4040
import { RouteHandlerRegistry } from './RouteHandlerRegistry.js';
@@ -399,14 +399,14 @@ class Router {
399399
headers: { 'Content-Type': 'application/json' },
400400
});
401401
} catch (handlerError) {
402-
if (handlerError instanceof ServiceError) {
402+
if (handlerError instanceof HttpError) {
403403
return await this.handleError(handlerError, options);
404404
}
405405
return this.#defaultErrorHandler(handlerError as Error);
406406
}
407407
}
408408

409-
if (error instanceof ServiceError) {
409+
if (error instanceof HttpError) {
410410
return new Response(JSON.stringify(error.toJSON()), {
411411
status: error.statusCode,
412412
headers: { 'Content-Type': 'application/json' },

packages/event-handler/src/rest/errors.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ParameterValidationError extends RouteMatchingError {
2020
}
2121
}
2222

23-
abstract class ServiceError extends Error {
23+
abstract class HttpError extends Error {
2424
abstract readonly statusCode: HttpStatusCode;
2525
abstract readonly errorType: string;
2626
public readonly details?: Record<string, unknown>;
@@ -31,7 +31,7 @@ abstract class ServiceError extends Error {
3131
details?: Record<string, unknown>
3232
) {
3333
super(message, options);
34-
this.name = 'ServiceError';
34+
this.name = 'HttpError';
3535
this.details = details;
3636
}
3737

@@ -47,7 +47,7 @@ abstract class ServiceError extends Error {
4747
}
4848
}
4949

50-
class BadRequestError extends ServiceError {
50+
class BadRequestError extends HttpError {
5151
readonly statusCode = HttpStatusCodes.BAD_REQUEST;
5252
readonly errorType = 'BadRequestError';
5353

@@ -61,7 +61,7 @@ class BadRequestError extends ServiceError {
6161
}
6262
}
6363

64-
class UnauthorizedError extends ServiceError {
64+
class UnauthorizedError extends HttpError {
6565
readonly statusCode = HttpStatusCodes.UNAUTHORIZED;
6666
readonly errorType = 'UnauthorizedError';
6767

@@ -75,7 +75,7 @@ class UnauthorizedError extends ServiceError {
7575
}
7676
}
7777

78-
class ForbiddenError extends ServiceError {
78+
class ForbiddenError extends HttpError {
7979
readonly statusCode = HttpStatusCodes.FORBIDDEN;
8080
readonly errorType = 'ForbiddenError';
8181

@@ -89,7 +89,7 @@ class ForbiddenError extends ServiceError {
8989
}
9090
}
9191

92-
class NotFoundError extends ServiceError {
92+
class NotFoundError extends HttpError {
9393
readonly statusCode = HttpStatusCodes.NOT_FOUND;
9494
readonly errorType = 'NotFoundError';
9595

@@ -103,7 +103,7 @@ class NotFoundError extends ServiceError {
103103
}
104104
}
105105

106-
class MethodNotAllowedError extends ServiceError {
106+
class MethodNotAllowedError extends HttpError {
107107
readonly statusCode = HttpStatusCodes.METHOD_NOT_ALLOWED;
108108
readonly errorType = 'MethodNotAllowedError';
109109

@@ -117,7 +117,7 @@ class MethodNotAllowedError extends ServiceError {
117117
}
118118
}
119119

120-
class RequestTimeoutError extends ServiceError {
120+
class RequestTimeoutError extends HttpError {
121121
readonly statusCode = HttpStatusCodes.REQUEST_TIMEOUT;
122122
readonly errorType = 'RequestTimeoutError';
123123

@@ -131,7 +131,7 @@ class RequestTimeoutError extends ServiceError {
131131
}
132132
}
133133

134-
class RequestEntityTooLargeError extends ServiceError {
134+
class RequestEntityTooLargeError extends HttpError {
135135
readonly statusCode = HttpStatusCodes.REQUEST_ENTITY_TOO_LARGE;
136136
readonly errorType = 'RequestEntityTooLargeError';
137137

@@ -145,7 +145,7 @@ class RequestEntityTooLargeError extends ServiceError {
145145
}
146146
}
147147

148-
class InternalServerError extends ServiceError {
148+
class InternalServerError extends HttpError {
149149
readonly statusCode = HttpStatusCodes.INTERNAL_SERVER_ERROR;
150150
readonly errorType = 'InternalServerError';
151151

@@ -159,7 +159,7 @@ class InternalServerError extends ServiceError {
159159
}
160160
}
161161

162-
class ServiceUnavailableError extends ServiceError {
162+
class ServiceUnavailableError extends HttpError {
163163
readonly statusCode = HttpStatusCodes.SERVICE_UNAVAILABLE;
164164
readonly errorType = 'ServiceUnavailableError';
165165

@@ -183,7 +183,7 @@ export {
183183
RequestEntityTooLargeError,
184184
RequestTimeoutError,
185185
RouteMatchingError,
186-
ServiceError,
186+
HttpError,
187187
ServiceUnavailableError,
188188
UnauthorizedError,
189189
};

packages/event-handler/src/rest/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ export {
88
export {
99
BadRequestError,
1010
ForbiddenError,
11+
HttpError,
1112
InternalServerError,
1213
MethodNotAllowedError,
1314
NotFoundError,
1415
ParameterValidationError,
1516
RequestEntityTooLargeError,
1617
RequestTimeoutError,
1718
RouteMatchingError,
18-
ServiceError,
1919
ServiceUnavailableError,
2020
UnauthorizedError,
2121
} from './errors.js';

packages/event-handler/tests/unit/rest/Router/error-handling.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe('Class: Router - Error Handling', () => {
182182
});
183183
});
184184

185-
it('uses ServiceError toJSON method when no custom handler is registered', async () => {
185+
it('uses HttpError toJSON method when no custom handler is registered', async () => {
186186
// Prepare
187187
const app = new Router();
188188

0 commit comments

Comments
 (0)