diff --git a/.changeset/short-colts-beg.md b/.changeset/short-colts-beg.md new file mode 100644 index 000000000..d8ab3516f --- /dev/null +++ b/.changeset/short-colts-beg.md @@ -0,0 +1,5 @@ +--- +"@onflow/transport-http": minor +--- + +Added errorMessage property to HTTPRequestError to expose Access API errors when making requests diff --git a/packages/transport-http/src/http-request.js b/packages/transport-http/src/http-request.js index 6b9db47b8..9b163412d 100644 --- a/packages/transport-http/src/http-request.js +++ b/packages/transport-http/src/http-request.js @@ -21,16 +21,18 @@ class HTTPRequestError extends Error { ${error ? `error=${error}` : ""} ${hostname ? `hostname=${hostname}` : ""} ${path ? `path=${path}` : ""} + ${port ? `port=${port}` : ""} ${method ? `method=${method}` : ""} ${requestBody ? `requestBody=${JSON.stringify(requestBody)}` : ""} - ${responseBody ? `responseBody=${responseBody}` : ""} + ${responseBody ? `responseBody=${JSON.stringify(responseBody)}` : ""} ${responseStatusText ? `responseStatusText=${responseStatusText}` : ""} ${reqOn ? `reqOn=${reqOn}` : ""} ${statusCode ? `statusCode=${statusCode}` : ""} ` super(msg) this.name = "HTTP Request Error" - this.statusCode = statusCode + this.statusCode = responseBody?.code ?? statusCode + this.errorMessage = responseBody?.message } } @@ -105,7 +107,7 @@ export async function httpRequest({ if (res.ok) { return res.json() } - const responseJSON = JSON.stringify(await res.json()) + const responseJSON = await res.json() throw new HTTPRequestError({ transport: "FetchTransport", error: responseJSON?.message, @@ -204,6 +206,8 @@ export async function httpRequest({ path, port, method, + requestBody: body ?? null, + responseBody: responseBody, reqOn: "end", }) )