Skip to content

Commit 4bf4637

Browse files
authored
fix(typescript-fetch): ResponseError prototype chain (#23010)
* fix(typescript-fetch): ResponseError prototype chain * samples/*/typescript-fetch: re-generate runtime.ts
1 parent c3c17bb commit 4bf4637

20 files changed

Lines changed: 350 additions & 1 deletion

File tree

modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,38 @@ export class ResponseError extends Error {
251251
override name: "ResponseError" = "ResponseError";
252252
constructor(public response: Response, msg?: string) {
253253
super(msg);
254+
255+
// restore prototype chain
256+
const actualProto = new.target.prototype;
257+
if (Object.setPrototypeOf) {
258+
Object.setPrototypeOf(this, actualProto);
259+
}
254260
}
255261
}
256262

257263
export class FetchError extends Error {
258264
override name: "FetchError" = "FetchError";
259265
constructor(public cause: Error, msg?: string) {
260266
super(msg);
267+
268+
// restore prototype chain
269+
const actualProto = new.target.prototype;
270+
if (Object.setPrototypeOf) {
271+
Object.setPrototypeOf(this, actualProto);
272+
}
261273
}
262274
}
263275

264276
export class RequiredError extends Error {
265277
override name: "RequiredError" = "RequiredError";
266278
constructor(public field: string, msg?: string) {
267279
super(msg);
280+
281+
// restore prototype chain
282+
const actualProto = new.target.prototype;
283+
if (Object.setPrototypeOf) {
284+
Object.setPrototypeOf(this, actualProto);
285+
}
268286
}
269287
}
270288

samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,38 @@ export class ResponseError extends Error {
261261
override name: "ResponseError" = "ResponseError";
262262
constructor(public response: Response, msg?: string) {
263263
super(msg);
264+
265+
// restore prototype chain
266+
const actualProto = new.target.prototype;
267+
if (Object.setPrototypeOf) {
268+
Object.setPrototypeOf(this, actualProto);
269+
}
264270
}
265271
}
266272

267273
export class FetchError extends Error {
268274
override name: "FetchError" = "FetchError";
269275
constructor(public cause: Error, msg?: string) {
270276
super(msg);
277+
278+
// restore prototype chain
279+
const actualProto = new.target.prototype;
280+
if (Object.setPrototypeOf) {
281+
Object.setPrototypeOf(this, actualProto);
282+
}
271283
}
272284
}
273285

274286
export class RequiredError extends Error {
275287
override name: "RequiredError" = "RequiredError";
276288
constructor(public field: string, msg?: string) {
277289
super(msg);
290+
291+
// restore prototype chain
292+
const actualProto = new.target.prototype;
293+
if (Object.setPrototypeOf) {
294+
Object.setPrototypeOf(this, actualProto);
295+
}
278296
}
279297
}
280298

samples/client/others/typescript-fetch/self-import-issue/runtime.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,38 @@ export class ResponseError extends Error {
261261
override name: "ResponseError" = "ResponseError";
262262
constructor(public response: Response, msg?: string) {
263263
super(msg);
264+
265+
// restore prototype chain
266+
const actualProto = new.target.prototype;
267+
if (Object.setPrototypeOf) {
268+
Object.setPrototypeOf(this, actualProto);
269+
}
264270
}
265271
}
266272

267273
export class FetchError extends Error {
268274
override name: "FetchError" = "FetchError";
269275
constructor(public cause: Error, msg?: string) {
270276
super(msg);
277+
278+
// restore prototype chain
279+
const actualProto = new.target.prototype;
280+
if (Object.setPrototypeOf) {
281+
Object.setPrototypeOf(this, actualProto);
282+
}
271283
}
272284
}
273285

274286
export class RequiredError extends Error {
275287
override name: "RequiredError" = "RequiredError";
276288
constructor(public field: string, msg?: string) {
277289
super(msg);
290+
291+
// restore prototype chain
292+
const actualProto = new.target.prototype;
293+
if (Object.setPrototypeOf) {
294+
Object.setPrototypeOf(this, actualProto);
295+
}
278296
}
279297
}
280298

samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,38 @@ export class ResponseError extends Error {
261261
override name: "ResponseError" = "ResponseError";
262262
constructor(public response: Response, msg?: string) {
263263
super(msg);
264+
265+
// restore prototype chain
266+
const actualProto = new.target.prototype;
267+
if (Object.setPrototypeOf) {
268+
Object.setPrototypeOf(this, actualProto);
269+
}
264270
}
265271
}
266272

267273
export class FetchError extends Error {
268274
override name: "FetchError" = "FetchError";
269275
constructor(public cause: Error, msg?: string) {
270276
super(msg);
277+
278+
// restore prototype chain
279+
const actualProto = new.target.prototype;
280+
if (Object.setPrototypeOf) {
281+
Object.setPrototypeOf(this, actualProto);
282+
}
271283
}
272284
}
273285

274286
export class RequiredError extends Error {
275287
override name: "RequiredError" = "RequiredError";
276288
constructor(public field: string, msg?: string) {
277289
super(msg);
290+
291+
// restore prototype chain
292+
const actualProto = new.target.prototype;
293+
if (Object.setPrototypeOf) {
294+
Object.setPrototypeOf(this, actualProto);
295+
}
278296
}
279297
}
280298

samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,38 @@ export class ResponseError extends Error {
261261
override name: "ResponseError" = "ResponseError";
262262
constructor(public response: Response, msg?: string) {
263263
super(msg);
264+
265+
// restore prototype chain
266+
const actualProto = new.target.prototype;
267+
if (Object.setPrototypeOf) {
268+
Object.setPrototypeOf(this, actualProto);
269+
}
264270
}
265271
}
266272

267273
export class FetchError extends Error {
268274
override name: "FetchError" = "FetchError";
269275
constructor(public cause: Error, msg?: string) {
270276
super(msg);
277+
278+
// restore prototype chain
279+
const actualProto = new.target.prototype;
280+
if (Object.setPrototypeOf) {
281+
Object.setPrototypeOf(this, actualProto);
282+
}
271283
}
272284
}
273285

274286
export class RequiredError extends Error {
275287
override name: "RequiredError" = "RequiredError";
276288
constructor(public field: string, msg?: string) {
277289
super(msg);
290+
291+
// restore prototype chain
292+
const actualProto = new.target.prototype;
293+
if (Object.setPrototypeOf) {
294+
Object.setPrototypeOf(this, actualProto);
295+
}
278296
}
279297
}
280298

samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,38 @@ export class ResponseError extends Error {
261261
override name: "ResponseError" = "ResponseError";
262262
constructor(public response: Response, msg?: string) {
263263
super(msg);
264+
265+
// restore prototype chain
266+
const actualProto = new.target.prototype;
267+
if (Object.setPrototypeOf) {
268+
Object.setPrototypeOf(this, actualProto);
269+
}
264270
}
265271
}
266272

267273
export class FetchError extends Error {
268274
override name: "FetchError" = "FetchError";
269275
constructor(public cause: Error, msg?: string) {
270276
super(msg);
277+
278+
// restore prototype chain
279+
const actualProto = new.target.prototype;
280+
if (Object.setPrototypeOf) {
281+
Object.setPrototypeOf(this, actualProto);
282+
}
271283
}
272284
}
273285

274286
export class RequiredError extends Error {
275287
override name: "RequiredError" = "RequiredError";
276288
constructor(public field: string, msg?: string) {
277289
super(msg);
290+
291+
// restore prototype chain
292+
const actualProto = new.target.prototype;
293+
if (Object.setPrototypeOf) {
294+
Object.setPrototypeOf(this, actualProto);
295+
}
278296
}
279297
}
280298

samples/client/petstore/typescript-fetch/builds/default/runtime.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,38 @@ export class ResponseError extends Error {
261261
override name: "ResponseError" = "ResponseError";
262262
constructor(public response: Response, msg?: string) {
263263
super(msg);
264+
265+
// restore prototype chain
266+
const actualProto = new.target.prototype;
267+
if (Object.setPrototypeOf) {
268+
Object.setPrototypeOf(this, actualProto);
269+
}
264270
}
265271
}
266272

267273
export class FetchError extends Error {
268274
override name: "FetchError" = "FetchError";
269275
constructor(public cause: Error, msg?: string) {
270276
super(msg);
277+
278+
// restore prototype chain
279+
const actualProto = new.target.prototype;
280+
if (Object.setPrototypeOf) {
281+
Object.setPrototypeOf(this, actualProto);
282+
}
271283
}
272284
}
273285

274286
export class RequiredError extends Error {
275287
override name: "RequiredError" = "RequiredError";
276288
constructor(public field: string, msg?: string) {
277289
super(msg);
290+
291+
// restore prototype chain
292+
const actualProto = new.target.prototype;
293+
if (Object.setPrototypeOf) {
294+
Object.setPrototypeOf(this, actualProto);
295+
}
278296
}
279297
}
280298

samples/client/petstore/typescript-fetch/builds/enum/runtime.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,38 @@ export class ResponseError extends Error {
261261
override name: "ResponseError" = "ResponseError";
262262
constructor(public response: Response, msg?: string) {
263263
super(msg);
264+
265+
// restore prototype chain
266+
const actualProto = new.target.prototype;
267+
if (Object.setPrototypeOf) {
268+
Object.setPrototypeOf(this, actualProto);
269+
}
264270
}
265271
}
266272

267273
export class FetchError extends Error {
268274
override name: "FetchError" = "FetchError";
269275
constructor(public cause: Error, msg?: string) {
270276
super(msg);
277+
278+
// restore prototype chain
279+
const actualProto = new.target.prototype;
280+
if (Object.setPrototypeOf) {
281+
Object.setPrototypeOf(this, actualProto);
282+
}
271283
}
272284
}
273285

274286
export class RequiredError extends Error {
275287
override name: "RequiredError" = "RequiredError";
276288
constructor(public field: string, msg?: string) {
277289
super(msg);
290+
291+
// restore prototype chain
292+
const actualProto = new.target.prototype;
293+
if (Object.setPrototypeOf) {
294+
Object.setPrototypeOf(this, actualProto);
295+
}
278296
}
279297
}
280298

samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,38 @@ export class ResponseError extends Error {
261261
override name: "ResponseError" = "ResponseError";
262262
constructor(public response: Response, msg?: string) {
263263
super(msg);
264+
265+
// restore prototype chain
266+
const actualProto = new.target.prototype;
267+
if (Object.setPrototypeOf) {
268+
Object.setPrototypeOf(this, actualProto);
269+
}
264270
}
265271
}
266272

267273
export class FetchError extends Error {
268274
override name: "FetchError" = "FetchError";
269275
constructor(public cause: Error, msg?: string) {
270276
super(msg);
277+
278+
// restore prototype chain
279+
const actualProto = new.target.prototype;
280+
if (Object.setPrototypeOf) {
281+
Object.setPrototypeOf(this, actualProto);
282+
}
271283
}
272284
}
273285

274286
export class RequiredError extends Error {
275287
override name: "RequiredError" = "RequiredError";
276288
constructor(public field: string, msg?: string) {
277289
super(msg);
290+
291+
// restore prototype chain
292+
const actualProto = new.target.prototype;
293+
if (Object.setPrototypeOf) {
294+
Object.setPrototypeOf(this, actualProto);
295+
}
278296
}
279297
}
280298

samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,38 @@ export class ResponseError extends Error {
261261
override name: "ResponseError" = "ResponseError";
262262
constructor(public response: Response, msg?: string) {
263263
super(msg);
264+
265+
// restore prototype chain
266+
const actualProto = new.target.prototype;
267+
if (Object.setPrototypeOf) {
268+
Object.setPrototypeOf(this, actualProto);
269+
}
264270
}
265271
}
266272

267273
export class FetchError extends Error {
268274
override name: "FetchError" = "FetchError";
269275
constructor(public cause: Error, msg?: string) {
270276
super(msg);
277+
278+
// restore prototype chain
279+
const actualProto = new.target.prototype;
280+
if (Object.setPrototypeOf) {
281+
Object.setPrototypeOf(this, actualProto);
282+
}
271283
}
272284
}
273285

274286
export class RequiredError extends Error {
275287
override name: "RequiredError" = "RequiredError";
276288
constructor(public field: string, msg?: string) {
277289
super(msg);
290+
291+
// restore prototype chain
292+
const actualProto = new.target.prototype;
293+
if (Object.setPrototypeOf) {
294+
Object.setPrototypeOf(this, actualProto);
295+
}
278296
}
279297
}
280298

0 commit comments

Comments
 (0)