From 78d8fb056f2e8d141b5299eba75a990c6419076c Mon Sep 17 00:00:00 2001 From: lenkan Date: Thu, 25 Jan 2024 15:36:05 +0100 Subject: [PATCH 1/2] chore: add http status information in error message --- src/keri/app/clienting.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/keri/app/clienting.ts b/src/keri/app/clienting.ts index 1e3a6e69..20b8e8d2 100644 --- a/src/keri/app/clienting.ts +++ b/src/keri/app/clienting.ts @@ -210,7 +210,8 @@ export class SignifyClient { }); if (!res.ok) { const error = await res.text(); - throw new Error(error); + const message = `HTTP ${method} ${path} - ${res.status} ${res.statusText} - ${error}`; + throw new Error(message); } const isSameAgent = this.agent?.pre === res.headers.get('signify-resource'); From dfd37b00867363cfb60b27f06d276608766c2bfe Mon Sep 17 00:00:00 2001 From: lenkan Date: Thu, 25 Jan 2024 15:42:37 +0100 Subject: [PATCH 2/2] add unit test for http status info --- test/app/clienting.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/app/clienting.test.ts b/test/app/clienting.test.ts index 1506b4c8..ede08d6f 100644 --- a/test/app/clienting.test.ts +++ b/test/app/clienting.test.ts @@ -377,4 +377,29 @@ describe('SignifyClient', () => { 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK' ); }); + + test('includes HTTP status info in error message', async () => { + await libsodium.ready; + const bran = '0123456789abcdefghijk'; + const client = new SignifyClient(url, bran, Tier.low, boot_url); + + await client.connect(); + + fetchMock.mockResolvedValue( + new Response('Error info', { + status: 400, + statusText: 'Bad Request', + }) + ); + + const error = await client + .fetch('/somepath', 'GET', undefined) + .catch((e) => e); + + assert(error instanceof Error); + assert.equal( + error.message, + 'HTTP GET /somepath - 400 Bad Request - Error info' + ); + }); });