Skip to content

Commit

Permalink
fix: don't unwrap response from /version
Browse files Browse the repository at this point in the history
  • Loading branch information
yusefnapora committed Apr 29, 2022
1 parent 734b42b commit 48b0a1d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/website/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ export async function getUserTags() {
* @returns {Promise<VersionInfo>} (async) version information for API service
*/
export async function getVersion() {
return (await fetchRoute('/version')).value
// the '/version' route doesn't wrap its response in `{ ok, value }` like `fetchRoute` expects
const res = await fetch(API + '/version')
if (!res.ok) {
throw new Error(`HTTP error: [${res.status}] ${res.statusText}`)
}
return res.json()
}

/**
Expand Down Expand Up @@ -204,6 +209,11 @@ async function fetchRoute(route, fetchOptions = {}) {
if (body.ok) {
return body
} else {
throw new Error(body.error.message)
if (body.error && body.error.message) {
throw new Error(body.error.message)
}
throw new Error(
`unexpected response: ok != true, but body is missing error message`
)
}
}

0 comments on commit 48b0a1d

Please sign in to comment.