Skip to content

Commit f656aba

Browse files
committed
Improve graphql error logging
1 parent 9510f7b commit f656aba

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

packages/skin-museum-client/src/utils.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,34 @@ export function filenameIsReadme(filename) {
9393
}
9494

9595
// Tools like Prettier can infer that a string is GraphQL if it uses this tagged
96-
// template liteal.
96+
// template literal.
9797
export function gql(strings) {
9898
return strings[0];
9999
}
100100

101101
export async function fetchGraphql(query, variables = {}) {
102102
const url = `${API_URL}/graphql`;
103-
const response = await fetch(url, {
104-
method: "POST",
105-
headers: {
106-
"Content-Type": "application/json",
107-
Accept: "application/json",
108-
},
109-
mode: "cors",
110-
credentials: "include",
111-
body: JSON.stringify({ query, variables }),
112-
});
103+
let response;
104+
try {
105+
response = await fetch(url, {
106+
method: "POST",
107+
headers: {
108+
"Content-Type": "application/json",
109+
Accept: "application/json",
110+
},
111+
mode: "cors",
112+
credentials: "include",
113+
body: JSON.stringify({ query, variables }),
114+
});
115+
} catch (error) {
116+
console.error("Failed to fetch", {
117+
message: error.message,
118+
url,
119+
query,
120+
variables,
121+
});
122+
throw error;
123+
}
113124
if (response.status === 403) {
114125
window.location = `${API_URL}/auth`;
115126
}

0 commit comments

Comments
 (0)