Skip to content

Commit 82c6f6e

Browse files
committed
Bugfix: Errors should have correct name for toString() and have messages possibly containing payload message
1 parent 28a6b0b commit 82c6f6e

File tree

11 files changed

+71
-118
lines changed

11 files changed

+71
-118
lines changed

snapshotTests/snapshot/example/base.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,52 +126,43 @@ type QueryParams = Record<string, string | string[] | Date | Date[] | boolean |
126126
type QueryOptions = Record<string, { explode?: boolean; delimiter?: "," | " " | "|", format?: "date" }>;
127127

128128
export class HttpError extends Error {
129-
readonly response: Response;
130-
readonly body: any;
131-
132-
constructor(response: Response, body?: any) {
133-
super(response.statusText);
134-
this.response = response;
135-
this.body = body;
136-
Object.setPrototypeOf(this, HttpError.prototype);
129+
constructor(public readonly response: Response, public readonly body?: any) {
130+
super(body?.message || response.statusText || response.status);
131+
this.name = new.target.name;
132+
Object.setPrototypeOf(this, new.target.prototype);
137133
}
138134
}
139135

140136
export class ServerError extends HttpError {
141137
constructor(response: Response, body: any) {
142138
super(response, body);
143-
Object.setPrototypeOf(this, ServerError.prototype);
144139
}
145140
}
146141

147142
export class RequestError extends HttpError {
148143
constructor(response: Response, body: any) {
149144
super(response, body);
150-
Object.setPrototypeOf(this, RequestError.prototype);
151145
}
152146
}
153147

154148
export class LoggedOutError extends RequestError {
155149
constructor(response: Response, body: any) {
156150
super(response, body);
157-
Object.setPrototypeOf(this, LoggedOutError.prototype);
158151
}
159152
}
160153

161154
export class NotFoundError extends RequestError {
162155
constructor(response: Response, body: any) {
163156
super(response, body);
164-
Object.setPrototypeOf(this, NotFoundError.prototype);
165157
}
166158
}
167159

168160
export class RedirectedError extends HttpError {
169161
constructor(response: Response) {
170162
super(response);
171-
Object.setPrototypeOf(this, RedirectedError.prototype);
172163
}
173164
}
174165

175166
export interface SecurityScheme {
176167
headers(): Record<string, string>;
177-
}
168+
}

snapshotTests/snapshot/geojson/base.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,52 +126,43 @@ type QueryParams = Record<string, string | string[] | Date | Date[] | boolean |
126126
type QueryOptions = Record<string, { explode?: boolean; delimiter?: "," | " " | "|", format?: "date" }>;
127127

128128
export class HttpError extends Error {
129-
readonly response: Response;
130-
readonly body: any;
131-
132-
constructor(response: Response, body?: any) {
133-
super(response.statusText);
134-
this.response = response;
135-
this.body = body;
136-
Object.setPrototypeOf(this, HttpError.prototype);
129+
constructor(public readonly response: Response, public readonly body?: any) {
130+
super(body?.message || response.statusText || response.status);
131+
this.name = new.target.name;
132+
Object.setPrototypeOf(this, new.target.prototype);
137133
}
138134
}
139135

140136
export class ServerError extends HttpError {
141137
constructor(response: Response, body: any) {
142138
super(response, body);
143-
Object.setPrototypeOf(this, ServerError.prototype);
144139
}
145140
}
146141

147142
export class RequestError extends HttpError {
148143
constructor(response: Response, body: any) {
149144
super(response, body);
150-
Object.setPrototypeOf(this, RequestError.prototype);
151145
}
152146
}
153147

154148
export class LoggedOutError extends RequestError {
155149
constructor(response: Response, body: any) {
156150
super(response, body);
157-
Object.setPrototypeOf(this, LoggedOutError.prototype);
158151
}
159152
}
160153

161154
export class NotFoundError extends RequestError {
162155
constructor(response: Response, body: any) {
163156
super(response, body);
164-
Object.setPrototypeOf(this, NotFoundError.prototype);
165157
}
166158
}
167159

168160
export class RedirectedError extends HttpError {
169161
constructor(response: Response) {
170162
super(response);
171-
Object.setPrototypeOf(this, RedirectedError.prototype);
172163
}
173164
}
174165

175166
export interface SecurityScheme {
176167
headers(): Record<string, string>;
177-
}
168+
}

snapshotTests/snapshot/infectionTracker/base.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,52 +126,43 @@ type QueryParams = Record<string, string | string[] | Date | Date[] | boolean |
126126
type QueryOptions = Record<string, { explode?: boolean; delimiter?: "," | " " | "|", format?: "date" }>;
127127

128128
export class HttpError extends Error {
129-
readonly response: Response;
130-
readonly body: any;
131-
132-
constructor(response: Response, body?: any) {
133-
super(response.statusText);
134-
this.response = response;
135-
this.body = body;
136-
Object.setPrototypeOf(this, HttpError.prototype);
129+
constructor(public readonly response: Response, public readonly body?: any) {
130+
super(body?.message || response.statusText || response.status);
131+
this.name = new.target.name;
132+
Object.setPrototypeOf(this, new.target.prototype);
137133
}
138134
}
139135

140136
export class ServerError extends HttpError {
141137
constructor(response: Response, body: any) {
142138
super(response, body);
143-
Object.setPrototypeOf(this, ServerError.prototype);
144139
}
145140
}
146141

147142
export class RequestError extends HttpError {
148143
constructor(response: Response, body: any) {
149144
super(response, body);
150-
Object.setPrototypeOf(this, RequestError.prototype);
151145
}
152146
}
153147

154148
export class LoggedOutError extends RequestError {
155149
constructor(response: Response, body: any) {
156150
super(response, body);
157-
Object.setPrototypeOf(this, LoggedOutError.prototype);
158151
}
159152
}
160153

161154
export class NotFoundError extends RequestError {
162155
constructor(response: Response, body: any) {
163156
super(response, body);
164-
Object.setPrototypeOf(this, NotFoundError.prototype);
165157
}
166158
}
167159

168160
export class RedirectedError extends HttpError {
169161
constructor(response: Response) {
170162
super(response);
171-
Object.setPrototypeOf(this, RedirectedError.prototype);
172163
}
173164
}
174165

175166
export interface SecurityScheme {
176167
headers(): Record<string, string>;
177-
}
168+
}

snapshotTests/snapshot/petstore/base.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,52 +126,43 @@ type QueryParams = Record<string, string | string[] | Date | Date[] | boolean |
126126
type QueryOptions = Record<string, { explode?: boolean; delimiter?: "," | " " | "|", format?: "date" }>;
127127

128128
export class HttpError extends Error {
129-
readonly response: Response;
130-
readonly body: any;
131-
132-
constructor(response: Response, body?: any) {
133-
super(response.statusText);
134-
this.response = response;
135-
this.body = body;
136-
Object.setPrototypeOf(this, HttpError.prototype);
129+
constructor(public readonly response: Response, public readonly body?: any) {
130+
super(body?.message || response.statusText || response.status);
131+
this.name = new.target.name;
132+
Object.setPrototypeOf(this, new.target.prototype);
137133
}
138134
}
139135

140136
export class ServerError extends HttpError {
141137
constructor(response: Response, body: any) {
142138
super(response, body);
143-
Object.setPrototypeOf(this, ServerError.prototype);
144139
}
145140
}
146141

147142
export class RequestError extends HttpError {
148143
constructor(response: Response, body: any) {
149144
super(response, body);
150-
Object.setPrototypeOf(this, RequestError.prototype);
151145
}
152146
}
153147

154148
export class LoggedOutError extends RequestError {
155149
constructor(response: Response, body: any) {
156150
super(response, body);
157-
Object.setPrototypeOf(this, LoggedOutError.prototype);
158151
}
159152
}
160153

161154
export class NotFoundError extends RequestError {
162155
constructor(response: Response, body: any) {
163156
super(response, body);
164-
Object.setPrototypeOf(this, NotFoundError.prototype);
165157
}
166158
}
167159

168160
export class RedirectedError extends HttpError {
169161
constructor(response: Response) {
170162
super(response);
171-
Object.setPrototypeOf(this, RedirectedError.prototype);
172163
}
173164
}
174165

175166
export interface SecurityScheme {
176167
headers(): Record<string, string>;
177-
}
168+
}

snapshotTests/snapshot/poly/base.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,52 +126,43 @@ type QueryParams = Record<string, string | string[] | Date | Date[] | boolean |
126126
type QueryOptions = Record<string, { explode?: boolean; delimiter?: "," | " " | "|", format?: "date" }>;
127127

128128
export class HttpError extends Error {
129-
readonly response: Response;
130-
readonly body: any;
131-
132-
constructor(response: Response, body?: any) {
133-
super(response.statusText);
134-
this.response = response;
135-
this.body = body;
136-
Object.setPrototypeOf(this, HttpError.prototype);
129+
constructor(public readonly response: Response, public readonly body?: any) {
130+
super(body?.message || response.statusText || response.status);
131+
this.name = new.target.name;
132+
Object.setPrototypeOf(this, new.target.prototype);
137133
}
138134
}
139135

140136
export class ServerError extends HttpError {
141137
constructor(response: Response, body: any) {
142138
super(response, body);
143-
Object.setPrototypeOf(this, ServerError.prototype);
144139
}
145140
}
146141

147142
export class RequestError extends HttpError {
148143
constructor(response: Response, body: any) {
149144
super(response, body);
150-
Object.setPrototypeOf(this, RequestError.prototype);
151145
}
152146
}
153147

154148
export class LoggedOutError extends RequestError {
155149
constructor(response: Response, body: any) {
156150
super(response, body);
157-
Object.setPrototypeOf(this, LoggedOutError.prototype);
158151
}
159152
}
160153

161154
export class NotFoundError extends RequestError {
162155
constructor(response: Response, body: any) {
163156
super(response, body);
164-
Object.setPrototypeOf(this, NotFoundError.prototype);
165157
}
166158
}
167159

168160
export class RedirectedError extends HttpError {
169161
constructor(response: Response) {
170162
super(response);
171-
Object.setPrototypeOf(this, RedirectedError.prototype);
172163
}
173164
}
174165

175166
export interface SecurityScheme {
176167
headers(): Record<string, string>;
177-
}
168+
}

snapshotTests/snapshot/typeHierarchy/base.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,52 +126,43 @@ type QueryParams = Record<string, string | string[] | Date | Date[] | boolean |
126126
type QueryOptions = Record<string, { explode?: boolean; delimiter?: "," | " " | "|", format?: "date" }>;
127127

128128
export class HttpError extends Error {
129-
readonly response: Response;
130-
readonly body: any;
131-
132-
constructor(response: Response, body?: any) {
133-
super(response.statusText);
134-
this.response = response;
135-
this.body = body;
136-
Object.setPrototypeOf(this, HttpError.prototype);
129+
constructor(public readonly response: Response, public readonly body?: any) {
130+
super(body?.message || response.statusText || response.status);
131+
this.name = new.target.name;
132+
Object.setPrototypeOf(this, new.target.prototype);
137133
}
138134
}
139135

140136
export class ServerError extends HttpError {
141137
constructor(response: Response, body: any) {
142138
super(response, body);
143-
Object.setPrototypeOf(this, ServerError.prototype);
144139
}
145140
}
146141

147142
export class RequestError extends HttpError {
148143
constructor(response: Response, body: any) {
149144
super(response, body);
150-
Object.setPrototypeOf(this, RequestError.prototype);
151145
}
152146
}
153147

154148
export class LoggedOutError extends RequestError {
155149
constructor(response: Response, body: any) {
156150
super(response, body);
157-
Object.setPrototypeOf(this, LoggedOutError.prototype);
158151
}
159152
}
160153

161154
export class NotFoundError extends RequestError {
162155
constructor(response: Response, body: any) {
163156
super(response, body);
164-
Object.setPrototypeOf(this, NotFoundError.prototype);
165157
}
166158
}
167159

168160
export class RedirectedError extends HttpError {
169161
constructor(response: Response) {
170162
super(response);
171-
Object.setPrototypeOf(this, RedirectedError.prototype);
172163
}
173164
}
174165

175166
export interface SecurityScheme {
176167
headers(): Record<string, string>;
177-
}
168+
}

0 commit comments

Comments
 (0)