mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
refactor(core) make message property (http errors) serializable
This commit is contained in:
@@ -9,7 +9,6 @@ import { isObject, isString } from '../utils/shared.utils';
|
||||
* @publicApi
|
||||
*/
|
||||
export class HttpException extends Error {
|
||||
public readonly message: any;
|
||||
/**
|
||||
* Instantiate a plain HTTP Exception.
|
||||
*
|
||||
@@ -40,7 +39,14 @@ export class HttpException extends Error {
|
||||
private readonly status: number,
|
||||
) {
|
||||
super();
|
||||
this.message = response;
|
||||
this.initMessage();
|
||||
}
|
||||
|
||||
public initMessage() {
|
||||
const defaultText = `HTTP Exception (response status code: ${this.status})`;
|
||||
this.message = isString(this.response)
|
||||
? `${defaultText} - ${this.response}`
|
||||
: defaultText;
|
||||
}
|
||||
|
||||
public getResponse(): string | object {
|
||||
@@ -51,15 +57,6 @@ export class HttpException extends Error {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
const message = this.getErrorString(this.message);
|
||||
return `Error: ${message}`;
|
||||
}
|
||||
|
||||
private getErrorString(target: string | object): string {
|
||||
return isString(target) ? target : JSON.stringify(target);
|
||||
}
|
||||
|
||||
public static createBody(
|
||||
message: object | string,
|
||||
error?: string,
|
||||
|
||||
Reference in New Issue
Block a user