Skip to content

Commit

Permalink
bugfix(common): http exceptions should have the same stacktrace as ge…
Browse files Browse the repository at this point in the history
…neric
  • Loading branch information
kamilmysliwiec committed Mar 27, 2019
1 parent 1a3d16a commit ca62dc9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
60 changes: 26 additions & 34 deletions integration/typegraphql/e2e/pipes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,20 @@ describe('GraphQL - Pipes', () => {
extensions: {
code: 'INTERNAL_SERVER_ERROR',
exception: {
message: {
error: 'Bad Request',
message: [
{
children: [],
constraints: {
length:
'description must be longer than or equal to 30 characters',
},
property: 'description',
target: {
ingredients: [],
title: 'test',
},
message: [
{
children: [],
constraints: {
length:
'description must be longer than or equal to 30 characters',
},
],
statusCode: 400,
},
property: 'description',
target: {
ingredients: [],
title: 'test',
},
},
],
response: {
error: 'Bad Request',
message: [
Expand Down Expand Up @@ -77,24 +73,20 @@ describe('GraphQL - Pipes', () => {
line: 2,
},
],
message: {
error: 'Bad Request',
message: [
{
children: [],
constraints: {
length:
'description must be longer than or equal to 30 characters',
},
property: 'description',
target: {
ingredients: [],
title: 'test',
},
message: [
{
children: [],
constraints: {
length:
'description must be longer than or equal to 30 characters',
},
],
statusCode: 400,
},
property: 'description',
target: {
ingredients: [],
title: 'test',
},
},
],
path: ['addRecipe'],
},
],
Expand Down
8 changes: 6 additions & 2 deletions packages/common/exceptions/http.exception.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { isObject } from '../utils/shared.utils';

export class HttpException extends Error {
public readonly message: any;

/**
* The base Nest Application exception, which is handled by the default Exceptions Handler.
* Base Nest application exception, which is handled by the default Exceptions Handler.
* If you throw an exception from your HTTP route handlers, Nest will map them to the appropriate HTTP response and send to the client.
*
* When `response` is an object:
Expand All @@ -20,7 +22,9 @@ export class HttpException extends Error {
private readonly status: number,
) {
super();
this.message = response;
this.message =
(isObject(response) && (response as { message?: string }).message) ||
response;
}

public getResponse(): string | object {
Expand Down

0 comments on commit ca62dc9

Please sign in to comment.