Skip to content

Commit fe7fa13

Browse files
author
Danial Manavi
committed
Fix invalid message property.
1 parent 18b7498 commit fe7fa13

8 files changed

Lines changed: 40 additions & 18 deletions

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.8",
3+
"version": "1.0.9",
44
"description": "Standard Error Library for JavaScript/TypeScript projects (NodeJS & Browsers)",
55
"main": "./dist/require/index.js",
66
"module": "./dist/import/index.js",

src/application.error.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import { ErrorOptions } from './types';
55
* Application Error
66
*/
77
export class ApplicationError extends BaseError {
8-
constructor(message: string, error?: Error, opts?: ErrorOptions) {
9-
super(message, error, opts);
8+
constructor(message?: string, error?: Error, opts?: ErrorOptions) {
9+
// initialize null/undefined properties
10+
const _message = message || ApplicationError.name;
11+
12+
super(_message, error, opts);
1013

1114
// set stacktrace
1215
Error.captureStackTrace(this, ApplicationError);

src/bad_request.http.error.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ export class HttpBadRequestError<TError = any> extends HttpError {
2929
opts?.statusMessage || getReasonPhrase(parentConstructorProps.statusCode);
3030
parentConstructorProps.isHandled = opts?.isHandled || false;
3131

32+
// initialize null/undefined properties
33+
const _message = message || HttpBadRequestError.name;
34+
3235
/* Call the constructor with overrided parameters */
33-
super(message, error, parentConstructorProps);
36+
super(_message, error, parentConstructorProps);
3437

3538
/* Class-specific parameters */
3639
this.clientErrors = opts?.clientErrors || [];

src/base.error.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ export abstract class BaseError extends Error {
77
public readonly code: ErrorCodeType;
88

99
constructor(message?: string, error?: Error, opts?: ErrorOptions) {
10+
// initialize null/undefined properties
11+
const _message = message || BaseError.name;
12+
1013
/* Initialization phase */
11-
super(message);
14+
super(_message);
1215

13-
this.message = message || BaseError.name;
16+
this.message = _message;
1417
this.stack = error?.stack;
1518
this.code = opts?.code || BaseError.name;
1619

src/forbidden.http.error.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ export class HttpForbiddenError<
3535
opts?.statusMessage || getReasonPhrase(parentConstructorProps.statusCode);
3636
parentConstructorProps.isHandled = opts?.isHandled || false;
3737

38+
// initialize null/undefined properties
39+
const _message = message || HttpForbiddenError.name;
40+
3841
/* Call the constructor with overridden parameters */
39-
super(message, error, parentConstructorProps);
42+
super(_message, error, parentConstructorProps);
4043

4144
/* Class-specific parameters */
4245
this.userId = userId;

src/http.error.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import statusCodes, { getReasonPhrase } from 'http-status-codes';
22

3-
import { BaseError } from './base.error';
3+
import { ApplicationError } from './application.error';
44
import { ErrorOptions } from './types';
55

66
export type HttpErrorOptions = ErrorOptions & {
@@ -20,8 +20,7 @@ export type HttpErrorOptions = ErrorOptions & {
2020
isHandled?: boolean;
2121
};
2222

23-
export class HttpError extends BaseError {
24-
23+
export class HttpError extends ApplicationError {
2524
/**
2625
* HTTP status regarding the error
2726
*/
@@ -38,11 +37,15 @@ export class HttpError extends BaseError {
3837
public readonly isHandled?: boolean;
3938

4039
constructor(message?: string, error?: Error, opts?: HttpErrorOptions) {
40+
// initialize null/undefined properties
41+
const _message = message || HttpError.name;
42+
4143
/* Initialization phase */
42-
super(message, error, opts);
44+
super(_message, error, opts);
4345

4446
this.statusCode = opts?.statusCode || statusCodes.INTERNAL_SERVER_ERROR;
45-
this.statusMessage = opts?.statusMessage || getReasonPhrase(this.statusCode);
47+
this.statusMessage =
48+
opts?.statusMessage || getReasonPhrase(this.statusCode);
4649
this.isHandled = opts?.isHandled || false;
4750

4851
// set stacktrace

src/missing_argument.error.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { ErrorOptions } from './types';
77
import { isNonEmptyString } from './util';
88

99
export type MissingArgumentErrorOptions = ErrorOptions & {
10-
1110
/**
1211
* Name of the argument
1312
*/
@@ -18,19 +17,24 @@ export type MissingArgumentErrorOptions = ErrorOptions & {
1817
* Missing Argument Error
1918
*/
2019
export class MissingArgumentError extends BaseError {
21-
2220
/**
2321
* Name of the argument
2422
*/
2523
public readonly argumentName: string;
2624

27-
constructor(message?: string, error?: Error, opts?: MissingArgumentErrorOptions) {
25+
constructor(
26+
message?: string,
27+
error?: Error,
28+
opts?: MissingArgumentErrorOptions,
29+
) {
2830
/* Initialization phase */
2931
if (isNonEmptyString(opts?.argumentName) === true) {
30-
throw new Error('The \'argumentName\' needs to be a non-empty string.')
32+
throw new Error("The 'argumentName' needs to be a non-empty string.");
3133
}
3234

33-
super(message || `'${opts?.argumentName}' is missing.`, error, { code: opts?.code || MissingArgumentError.name });
35+
super(message || `'${opts?.argumentName}' is missing.`, error, {
36+
code: opts?.code || MissingArgumentError.name,
37+
});
3438

3539
this.argumentName = opts?.argumentName!;
3640

src/not_found.http.error.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ export class HttpNotFoundError<
2828
opts?.statusMessage || getReasonPhrase(parentConstructorProps.statusCode);
2929
parentConstructorProps.isHandled = opts?.isHandled || false;
3030

31+
// initialize null/undefined properties
32+
const _message = message || HttpNotFoundError.name;
33+
3134
/* Call the constructor with overridden parameters */
32-
super(message, error, parentConstructorProps);
35+
super(_message, error, parentConstructorProps);
3336

3437
/* Class-specific parameters */
3538
this.resourceType = resourceType;

0 commit comments

Comments
 (0)