From c58a7bcef2b17301e0864ea05272379d7328e8dd Mon Sep 17 00:00:00 2001 From: vprintempsPei Date: Wed, 6 Nov 2024 20:49:02 +0100 Subject: [PATCH] Return httpStatus in the error object. --- src/wfs/endpoint.spec.ts | 6 +++--- src/wms/endpoint.spec.ts | 6 +++--- src/worker/utils.ts | 10 ++++++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/wfs/endpoint.spec.ts b/src/wfs/endpoint.spec.ts index f253970..9b4d000 100644 --- a/src/wfs/endpoint.spec.ts +++ b/src/wfs/endpoint.spec.ts @@ -80,9 +80,9 @@ describe('WfsEndpoint', () => { endpoint = new WfsEndpoint('https://my.test.service/ogc/wms'); }); it('rejects when the endpoint returns an exception report', async () => { - await expect(endpoint.isReady()).rejects.toThrow( - 'msWFSDispatch(): WFS server error. WFS request not enabled. Check wfs/ows_enable_request settings.' - ); + await expect(endpoint.isReady()).rejects.toMatchObject({ + message: 'msWFSDispatch(): WFS server error. WFS request not enabled. Check wfs/ows_enable_request settings.' + }); }); }); }); diff --git a/src/wms/endpoint.spec.ts b/src/wms/endpoint.spec.ts index 6b9a65d..44169d6 100644 --- a/src/wms/endpoint.spec.ts +++ b/src/wms/endpoint.spec.ts @@ -60,9 +60,9 @@ describe('WmsEndpoint', () => { endpoint = new WmsEndpoint('https://my.test.service/ogc/wfs'); }); it('rejects when the endpoint returns an exception report', async () => { - await expect(endpoint.isReady()).rejects.toThrow( - 'msWMSGetCapabilities(): WMS server error. WMS request not enabled. Check wms/ows_enable_request settings.' - ); + await expect(endpoint.isReady()).rejects.toMatchObject({ + message: 'msWMSGetCapabilities(): WMS server error. WMS request not enabled. Check wms/ows_enable_request settings.', + }); }); }); }); diff --git a/src/worker/utils.ts b/src/worker/utils.ts index e073629..f2aff71 100644 --- a/src/worker/utils.ts +++ b/src/worker/utils.ts @@ -1,4 +1,5 @@ import { getUniqueId } from '../shared/id.js'; +import { EndpointError } from '../shared/errors.js' type TaskParams = Record; type TaskResponse = Record; @@ -76,11 +77,16 @@ export function addTaskHandler( const eventHandler = async (request: WorkerRequest) => { if (request.taskName === taskName) { - let response, error; + let response; + let error: EndpointError; try { response = await handler(request.params); } catch (e) { - error = e; + error = { + httpStatus: e.httpStatus, + message: e.message, + name: e.name + }; } const message = /** @type {WorkerResponse} */ { taskName,