From 1c568ef81c800863ff3b15184472f4d790487aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=B8=D0=BC=D1=83=D1=80=20=D0=93=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B4=D0=B5=D1=86=D0=BA=D0=B8=D0=B9?= Date: Fri, 16 Oct 2026 08:58:17 +0500 Subject: [PATCH] fix: make HttpError detectable with instanceof MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SPFx compiles to ES5, where subclasses of Error lose their prototype, so `instanceof HttpError` was always false and the hub export showed the generic message instead of "Ошибка API: {status} {statusText}". Co-Authored-By: Claude Opus 5.5 (1M context) --- src/webparts/stroyBot/services/http/IHttpClient.test.ts | 9 +++++++++ src/webparts/stroyBot/services/http/IHttpClient.ts | 2 ++ 2 files changed, 11 insertions(+) create mode 100644 src/webparts/stroyBot/services/http/IHttpClient.test.ts 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; }