Skip to content

Commit

Permalink
Better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarrough committed Apr 19, 2024
1 parent bdd0d5d commit f534b44
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/pages/create/channel/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,14 @@ export default function PageNewChannelImport({dbSession: {radio4000ApiUrl, sessi
tokenSupabase,
}),
})

const data = await res.json()
console.log('api/import/firebase-realtime response data', data)
setMigrationResult(data)

if (Object.keys(data).length === 0) {
setError({message: 'Empty response from migration backend'})
} else if (data.code && data.message) {
setError(data)
} else {
setError(false)
}
console.log(res.ok, res.status, res.statusText, 'api/import/firebase-realtime response data', data)
if (!res.ok) throw Error(data.message)
if (Object.keys(data).length === 0) throw Error('Empty response from migration backend')
} catch (error) {
console.error('Error calling migration backend', error)
console.error(error)
setError(error)
} finally {
setLoading(false)
Expand Down

0 comments on commit f534b44

Please sign in to comment.