mirror of
https://github.com/captbaritone/webamp.git
synced 2026-01-23 10:15:31 +00:00
Improve graphql error logging
This commit is contained in:
parent
9510f7b37f
commit
f656aba7d9
1 changed files with 22 additions and 11 deletions
|
|
@ -93,23 +93,34 @@ export function filenameIsReadme(filename) {
|
|||
}
|
||||
|
||||
// Tools like Prettier can infer that a string is GraphQL if it uses this tagged
|
||||
// template liteal.
|
||||
// template literal.
|
||||
export function gql(strings) {
|
||||
return strings[0];
|
||||
}
|
||||
|
||||
export async function fetchGraphql(query, variables = {}) {
|
||||
const url = `${API_URL}/graphql`;
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
},
|
||||
mode: "cors",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({ query, variables }),
|
||||
});
|
||||
let response;
|
||||
try {
|
||||
response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
},
|
||||
mode: "cors",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({ query, variables }),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch", {
|
||||
message: error.message,
|
||||
url,
|
||||
query,
|
||||
variables,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
if (response.status === 403) {
|
||||
window.location = `${API_URL}/auth`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue