Created
March 4, 2018 07:57
-
-
Save akoenig/016c16471c955caa0f3e56c901667352 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// path: resolvers/helmet.ts | |
import { FatalError } from "./errors/FatalError"; | |
const helmet = (resolver) => async (...args) => { | |
try { | |
// | |
// Try to execute the actual resolver and return | |
// the result immediately. | |
// | |
return await resolver(...args); | |
} catch (err) { | |
// | |
// Due to the fact that we are using Prisma, we can assume | |
// that each error from this layer has a `path` attribute. | |
// | |
// Note: The `FatalError` has been created before by | |
// using `apollo-errors` `createError` function. | |
// | |
if (err.path) { | |
throw new FatalError({ data: { reason: err.message } }); | |
} else { | |
throw err; | |
} | |
} | |
}; | |
export { helmet }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment