Skip to content

Commit

Permalink
fix: fetch r.ok
Browse files Browse the repository at this point in the history
  • Loading branch information
theClarkSell committed Oct 12, 2023
1 parent a2d9e79 commit eeec82a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thatconference.com",
"version": "5.0.10",
"version": "5.0.11",
"description": "THATConference.com website",
"main": "index.js",
"type": "module",
Expand Down
31 changes: 15 additions & 16 deletions src/lib/gfetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ function init(fetch) {
// 'that-correlation-id': createCorrelationId()
};

const json = (r) => r.json();
const handleResult = (r) => {
if (browser) {
loading.set(false);
}

if (r.ok) {
return r.json();
} else {
Sentry.captureException(`${r.status} ${r.statusText}`);
throw new Error('API returned');
}
};

function updateHeaders(values) {
headers = {
Expand Down Expand Up @@ -55,11 +66,7 @@ function init(fetch) {
retries: 3,
retryOn
})
.then(json)
.then((r) => {
if (browser) loading.set(false);
return r;
})
.then(handleResult)
.catch((error) => {
console.error('api query error:', error);
Sentry.captureException(error);
Expand Down Expand Up @@ -87,11 +94,7 @@ function init(fetch) {
}),
retryOn
})
.then(json)
.then((r) => {
if (browser) loading.set(false);
return r;
})
.then(handleResult)
.catch((error) => {
console.error('api secure query error:', error);
Sentry.captureException(error);
Expand Down Expand Up @@ -119,11 +122,7 @@ function init(fetch) {
}),
retryOn
})
.then(json)
.then((r) => {
if (browser) loading.set(false);
return r;
})
.then(handleResult)
.catch((error) => {
console.error('api mutation error:', error);
Sentry.captureException(error);
Expand Down

0 comments on commit eeec82a

Please sign in to comment.