WebOfTrust/signify-ts

HTTP Status code is not included in error information

lenkan opened this issue · 0 comments

lenkan commented

Currently, the http status code is not included in the error information then signify client receives a non-OK response. See

if (!res.ok) {
const error = await res.text();
throw new Error(error);
}
.

This means you get a stack trace that does not include any information about the HTTP request and/or response:

Error:
   at SignifyClient.fetch...

I suggest to include the pathname, the status code, statusText in the error description. The response body can be included as a property on the error. For example

new Error(`HTTP ${method} ${pathname} - ${res.status} ${res.statusText}`, { cause: await response.text() });

Or create a new error type and add response body as a property.

class SignifyClientError extends Error {
    ...Some constructor that create appropriate error message and properties.
}