Skip to content

Commit

Permalink
Merge pull request #5859 from coder-freestyle/fix-set-name-property-o…
Browse files Browse the repository at this point in the history
…f-exception-object-equal-to-class-name

Fix set name property of exception object equal to class name
  • Loading branch information
kamilmysliwiec authored Jan 27, 2021
2 parents 275e71f + a69109e commit 5d01d22
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions integration/graphql-code-first/e2e/pipes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('GraphQL Pipes', () => {
code: 'INTERNAL_SERVER_ERROR',
exception: {
message: 'Bad Request Exception',
name: 'BadRequestException',
response: {
message: [
'description must be longer than or equal to 30 characters',
Expand Down
5 changes: 5 additions & 0 deletions packages/common/exceptions/http.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class HttpException extends Error {
) {
super();
this.initMessage();
this.initName();
}

public initMessage() {
Expand All @@ -56,6 +57,10 @@ export class HttpException extends Error {
.join(' ');
}
}

public initName(): void {
this.name = this.constructor.name;
}

public getResponse(): string | object {
return this.response;
Expand Down
10 changes: 6 additions & 4 deletions packages/common/test/exceptions/http.exception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('HttpException', () => {
it('should be serializable', () => {
const message = 'Some Error';
const error = new HttpException(message, 400);
expect(`${error}`).to.be.eql(`Error: ${message}`);
expect(`${error}`).to.be.eql(`HttpException: ${message}`);
});

describe('when "response" is an object', () => {
Expand All @@ -71,16 +71,18 @@ describe('HttpException', () => {
const error = new HttpException(obj, 400);
const badRequestError = new BadRequestException(obj);

expect(`${error}`).to.be.eql(`Error: Http Exception`);
expect(`${badRequestError}`).to.be.eql(`Error: Bad Request Exception`);
expect(`${error}`).to.be.eql(`HttpException: Http Exception`);
expect(`${badRequestError}`).to.be.eql(
`BadRequestException: Bad Request Exception`,
);
expect(`${error}`.includes('[object Object]')).to.not.be.true;
expect(`${badRequestError}`.includes('[object Object]')).to.not.be.true;
});
describe('otherwise', () => {
it('should concat strings', () => {
const test = 'test message';
const error = new HttpException(test, 400);
expect(`${error}`).to.be.eql(`Error: ${test}`);
expect(`${error}`).to.be.eql(`HttpException: ${test}`);
expect(`${error}`.includes('[object Object]')).to.not.be.true;
});
});
Expand Down
Empty file modified scripts/run-integration.sh
100644 → 100755
Empty file.

0 comments on commit 5d01d22

Please sign in to comment.