Skip to content

Commit

Permalink
Merge pull request #203 from lenkan/add-error-info
Browse files Browse the repository at this point in the history
chore: add http status information in error message
  • Loading branch information
pfeairheller authored Jan 29, 2024
2 parents 8b2fa68 + dfd37b0 commit 95981e4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/keri/app/clienting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
25 changes: 25 additions & 0 deletions test/app/clienting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
});

0 comments on commit 95981e4

Please sign in to comment.