Skip to content

Commit

Permalink
Classify entry point errors as fatal errors, cache for a longer time
Browse files Browse the repository at this point in the history
  • Loading branch information
pastelsky committed Aug 21, 2019
1 parent 37dbb6c commit 471e2f9
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions server/middlewares/results/error.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,33 +90,38 @@ async function errorHandler(ctx, next) {
}
break

case 'EntryPointError':
respondWithError(500, {
code: 'EntryPointError',
message: 'We could not guess a valid entry point for this package. ' +
'Perhaps the author hasn\'t specified one in its package.json ?',
})
break

case 'MissingDependencyError': {
case 'EntryPointError': {
const status = 500
const body = {
error: {
code: 'EntryPointError',
message: 'We could not guess a valid entry point for this package. ' +
'Perhaps the author hasn\'t specified one in its package.json ?',
}
}

ctx.cacheControl = {
maxAge: force ? 0 : CONFIG.CACHE.SIZE_API_ERROR_FATAL,
}

respondWithError(status, body.error)

debug('saved %s to failure cache', `${ctx.state.resolved.packageString}`)
failureCache.set(
`${ctx.state.packageString}`,
{ status, body },
)

break
}

case 'MissingDependencyError': {
const status = 500
const missingModules = arrayToSentence(
err.extra
.missingModules
.map(module => `\`<code>${module}</code>\``),
)

respondWithError(500, {
code: 'MissingDependencyError',
message: `This package (or this version) uses ${missingModules}, ` +
`but does not specify ${missingModules.length > 1 ? 'them' :
'it'} either as a dependency or a peer dependency`,
details: err,
})
const body = {
error: {
code: 'MissingDependencyError',
Expand All @@ -127,8 +132,11 @@ async function errorHandler(ctx, next) {
},
}

ctx.status = status
ctx.body = body
ctx.cacheControl = {
maxAge: force ? 0 : CONFIG.CACHE.SIZE_API_ERROR_FATAL,
}

respondWithError(status, body.error)

debug('saved %s to failure cache', `${ctx.state.resolved.packageString}`)
failureCache.set(
Expand Down

0 comments on commit 471e2f9

Please sign in to comment.