zbd-node icon indicating copy to clipboard operation
zbd-node copied to clipboard

Create a DEBUG environment variable to help with debugging errors.

Open miketwenty1 opened this issue 1 year ago • 1 comments

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.

miketwenty1 avatar Jul 15 '24 18:07 miketwenty1

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;
}

jackeveritt avatar Jul 15 '24 18:07 jackeveritt