Skip to content

Commit

Permalink
More detailed api request failed log
Browse files Browse the repository at this point in the history
  • Loading branch information
kubk committed Nov 3, 2023
1 parent 8f6d17d commit c78263e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export const request = async <Output, Input = object>(
body?: Input,
): Promise<Output> => {
const endpoint = `${trimEnd(baseUrl, "/")}/${trimStart(path, "/")}`;
const bodyAsString = body ? JSON.stringify(body) : undefined;

const response = await fetch(endpoint, {
method,
body: body ? JSON.stringify(body) : undefined,
body: bodyAsString,
headers: {
hash: WebApp.initData,
},
Expand All @@ -23,6 +24,6 @@ export const request = async <Output, Input = object>(
throw new Error(
`Non-successful status: ${
response.status
}. Endpoint: ${endpoint}. Error: ${await response.text()}`,
}. Endpoint: ${endpoint}. Request body: ${bodyAsString}. Error: ${await response.text()}`,
);
};

0 comments on commit c78263e

Please sign in to comment.