Skip to content

Instantly share code, notes, and snippets.

@akoenig
Created March 4, 2018 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akoenig/016c16471c955caa0f3e56c901667352 to your computer and use it in GitHub Desktop.
Save akoenig/016c16471c955caa0f3e56c901667352 to your computer and use it in GitHub Desktop.
// 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