Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix set name property of exception object equal to class name #5859

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.