Skip to content

Commit

Permalink
Merge pull request #479 from 1ifeworld/jawn/error_logging
Browse files Browse the repository at this point in the history
richer error logging
  • Loading branch information
jawndiego authored Feb 18, 2024
2 parents 174b450 + e83cbe0 commit 54a4db8
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions apps/site/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,27 @@ export async function relayRegisterFor(
/* MEDIA SERVICE */

export async function w3sUpload(body: FormData, authToken: string | null) {
const res = await fetch('https://river-media-service.up.railway.app/w3s', {
method: 'POST',
headers: authToken ? { Authorization: `Bearer ${authToken}` } : undefined,
body,
})
if (!res.ok) {
console.error('Could not upload file', await res.text())
throw new Error('Could not upload file')
try {
const res = await fetch('https://river-media-service.up.railway.app/w3s', {
method: 'POST',
headers: authToken ? { Authorization: `Bearer ${authToken}` } : undefined,
body,
})

if (res.status === 413) {
console.error('File too large')
throw new Error('File too large. Please try a smaller file.')
} else if (!res.ok) {
const errorText = await res.text()
console.error('Could not upload file', errorText)
throw new Error(`Could not upload file: ${res.status} ${res.statusText} - ${errorText}`)
}

return res.json()
} catch (error) {
console.error('Upload failed', error)
throw error
}
return res.json()
}

export async function uploadToMux(body: string, authToken: string | null) {
Expand All @@ -103,8 +114,8 @@ export async function uploadToMux(body: string, authToken: string | null) {
},
)
if (!res.ok) {
console.error('Could not process video', await res.text())
throw new Error('Could not process video')
console.error('Could not upload to Mux', await res.text())
throw new Error('Could not upload to Mux')
}
const muxResponseData = await res.json()

Expand Down

0 comments on commit 54a4db8

Please sign in to comment.