Skip to content

Commit

Permalink
fix: relay error messages for better visibility (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricokahler committed Apr 22, 2024
1 parent 6d57272 commit fdac3ab
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/AssetHandler.js
Expand Up @@ -180,6 +180,13 @@ class AssetHandler {
try {
stream = await requestStream(options)
} catch (err) {
const message = 'Failed to create asset stream'
if (typeof err.message === 'string') {
// try to re-assign the error message so the stack trace is more visible
err.message = `${message}: ${err.message}`
throw err
}

throw new Error('Failed create asset stream', {cause: err})
}

Expand All @@ -194,7 +201,14 @@ class AssetHandler {

throw new Error(errMsg)
} catch (err) {
throw new Error('Failed to parse error response from asset stream', {cause: err})
const message = 'Failed to parse error response from asset stream'
if (typeof err.message === 'string') {
// try to re-assign the error message so the stack trace is more visible
err.message = `${message}: ${err.message}`
throw err
}

throw new Error(message, {cause: err})
}
}

Expand All @@ -211,7 +225,14 @@ class AssetHandler {
md5 = res.md5
size = res.size
} catch (err) {
throw new Error('Failed to write asset stream to filesystem', {cause: err})
const message = 'Failed to write asset stream to filesystem'

if (typeof err.message === 'string') {
err.message = `${message}: ${err.message}`
throw err
}

throw new Error(message, {cause: err})
}

// Verify it against our downloaded stream to make sure we have the same copy
Expand Down

0 comments on commit fdac3ab

Please sign in to comment.