Skip to content

Commit

Permalink
fix: Show correct error when fetch fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitcheljager committed Feb 6, 2024
1 parent 7254058 commit db26477
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions app/javascript/src/fetch-rails.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ export default class FetchRails {
const response = await fetch(this.url, finalParams)
clearTimeout(timeoutID)
if (returnResponse) return response
if (!response.ok) {
const json = await response.json()
throw new Error(json?.length ? json : `${ response.status }: ${ response.statusText }.`)
}
if (!response.ok) throw new Error(`${ response.status }: ${ response.statusText }.`)

const data = await response.text()
return data
Expand Down

0 comments on commit db26477

Please sign in to comment.