Skip to content

Commit

Permalink
fix(core): fixed credentials handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Xairoo committed Sep 18, 2022
1 parent cd2dcd7 commit 2acbccb
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions apps/web/utils/fetcher.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
// Fetch function for SWR
export default async function fetcher({ url, method, token }) {
if (!url) {
throw new Error('Missing `url` key')
throw new Error("Missing `url` key");
}

const res = await fetch(url, {
method: method ? method : 'GET',
method: method ? method : "GET",
credentials: "include",
headers: {
...(token && { Authorization: `Bearer ${token}` }),
},
})
});

// If the status code is not in the range 200-299,
if (!res.ok) {
let error
if (process.env.NODE_ENV !== 'production') {
error = {}
error = new Error('An error occurred while fetching the data.')
let error;
if (process.env.NODE_ENV !== "production") {
error = {};
error = new Error("An error occurred while fetching the data.");
} else {
}
// Attach extra info to the error object.
error.info = await res.json()
error.status = res.status
if (process.env.NODE_ENV !== 'production') {
throw error
error.info = await res.json();
error.status = res.status;
if (process.env.NODE_ENV !== "production") {
throw error;
}
}

return res.json()
return res.json();
}

0 comments on commit 2acbccb

Please sign in to comment.