diff --git a/src/webparts/stroyBot/services/http/IHttpClient.test.ts b/src/webparts/stroyBot/services/http/IHttpClient.test.ts new file mode 100644 index 0000000..30a45c7 --- /dev/null +++ b/src/webparts/stroyBot/services/http/IHttpClient.test.ts @@ -0,0 +1,9 @@ +import { HttpError } from './IHttpClient'; + +describe('HttpError', () => { + it('распознаётся через instanceof (сборка в ES5 ломала это без setPrototypeOf)', () => { + const error: unknown = new HttpError(403, 'Forbidden'); + expect(error instanceof HttpError).toBe(true); + expect((error as HttpError).status).toEqual(403); + }); +}); diff --git a/src/webparts/stroyBot/services/http/IHttpClient.ts b/src/webparts/stroyBot/services/http/IHttpClient.ts index bbf745e..25137db 100644 --- a/src/webparts/stroyBot/services/http/IHttpClient.ts +++ b/src/webparts/stroyBot/services/http/IHttpClient.ts @@ -31,6 +31,8 @@ export class HttpError extends Error { constructor(status: number, statusText: string, details?: string) { super(details ? `${status} ${statusText}: ${details}` : `${status} ${statusText}`); + // Сборка SPFx компилирует в ES5: без этого `error instanceof HttpError` всегда false. + Object.setPrototypeOf(this, HttpError.prototype); this.status = status; this.statusText = statusText; }