zbd-node
zbd-node copied to clipboard
Create a DEBUG environment variable to help with debugging errors.
Problem: Currently if there is a JSON parse issue with one of our API responses we throw an error and have no idea of what the raw data is. ZBD uses AWS and has middleware infra that can return HTML pages with various errors.
Proposed Solution: It would be nice to have a DEBUG env flag that can be enabled to see the underlying problem in the logs. Specifically for sendPayment, but would be nice to expand for all endpoints.
The error I get is Unexpected token < in JSON at position 0 So could it be related to JSON.stringify(cleanup(body)), here:
export async function postData({
url,
body,
headers,
}: {
url: string;
body: any;
headers?: any;
}) {
const response = await fetch(url, {
method: "POST",
headers: {
'Content-Type': 'application/json',
...headers,
},
body: JSON.stringify(cleanup(body)),
});
if (!response.ok) {
const errorBody = await response.json();
const error = {
status: response.status,
message: errorBody.message || 'API request failed',
};
throw error;
}
const result = await response.json();
return result;
}