Skip to content

Commit 33c6adf

Browse files
author
Danial Manavi
committed
Add Error suffix to HttpBadRequest.
1 parent 582e8cb commit 33c6adf

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "error-lib",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Standard Error Library for JavaScript/TypeScript projects (NodeJS & Browsers)",
55
"main": "./dist/require/index.js",
66
"module": "./dist/import/index.js",

src/bad_request.http.error.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,30 @@ import statusCodes, { getReasonPhrase } from 'http-status-codes';
33
import { HttpError, HttpErrorOptions } from './http.error';
44

55
export type HttpBadRequestErrorOptions<TError = any> = HttpErrorOptions & {
6-
76
/**
87
* Client errors
98
*/
10-
clientErrors: Array<TError>
11-
}
12-
13-
export class HttpBadRequest<TError = any> extends HttpError {
9+
clientErrors: Array<TError>;
10+
};
1411

12+
export class HttpBadRequestError<TError = any> extends HttpError {
1513
/**
1614
* Client error(s)
1715
*/
1816
public readonly clientErrors: Array<TError>;
1917

20-
constructor(message?: string, error?: Error, opts?: HttpBadRequestErrorOptions) {
18+
constructor(
19+
message?: string,
20+
error?: Error,
21+
opts?: HttpBadRequestErrorOptions,
22+
) {
2123
/* Initialization phase */
2224
const parentConstructorProps: HttpErrorOptions = {
23-
statusCode: opts?.statusCode || statusCodes.BAD_REQUEST
25+
statusCode: opts?.statusCode || statusCodes.BAD_REQUEST,
2426
};
2527

26-
parentConstructorProps.statusMessage = opts?.statusMessage || getReasonPhrase(parentConstructorProps.statusCode);
28+
parentConstructorProps.statusMessage =
29+
opts?.statusMessage || getReasonPhrase(parentConstructorProps.statusCode);
2730
parentConstructorProps.isHandled = opts?.isHandled || false;
2831

2932
/* Call the constructor with overrided parameters */
@@ -33,9 +36,9 @@ export class HttpBadRequest<TError = any> extends HttpError {
3336
this.clientErrors = opts?.clientErrors || [];
3437

3538
// set stacktrace
36-
Error.captureStackTrace(this, HttpBadRequest);
39+
Error.captureStackTrace(this, HttpBadRequestError);
3740

3841
// Set prototype to make instanceOf enabled
39-
Object.setPrototypeOf(this, HttpBadRequest.prototype);
42+
Object.setPrototypeOf(this, HttpBadRequestError.prototype);
4043
}
4144
}

0 commit comments

Comments
 (0)