Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@vivareal/error-glossary
Advanced tools
Handler to format graphql errors into beautifully crafted user messages
A library to centralize and craft the messages for all errors coming from Gandalf
We have several client applications using Gandalf as a BFF and a lot of the logic related services and data fetching are replicated from project to project.
This library is an attempt to centralize and reuse the same error formating logic for all the Gandalf related projects. The benefits of doing this include:
The last item is specially important as this is a long time proposal discussed here, with more infos here and more recently here
npm i --save @vivareal/error-glossary
# or
yarn add @vivareal/error-glossary
Import and instantiate the ErrorGlossary
class into the file that manages graphql requests and error handling
Usually this is the lib/errors.js but if your use case is simple enough, you can plug the ErrorGlossary directly into the service.js file
import ErrorGlossary from '@vivareal/error-glossary'
const errorGlossary = new ErrorGlossary(app, options)
try {
service.graphql(...)
} catch (error) {
throw errorGlossary.getError(error);
}
Important to notice the getError
method expects an object with a property graphQLErrors
, which would be an array. Basically is what Apollo GraphQL return to the client. Errors that aren't GraphQL errors should not be passed here (Network Errors for instance), so please verify the error
object before passing to the getError
method.
app = 'CANALPRO' | 'OWNERS' | 'BACKOFFICE';
More applications can be added later
defaultError
. It will be used as a fallback in case the glossary don't find a given error from the backendconst options = {
defaultError: {
code: 'G0001',
message: 'Default Error',
statusCode: 400,
path: ['*'],
}
}
/**
* Get a formatted error from the glossary, else gets the default Error
* @param {Object} error - Graphql Error object directly from Apollo Client
* @param {Array.<Object>} error.graphQLErrors - Array of objects with error properties
* @param {string} error.graphQLErrors[].code - unique code from gandalf glossary
* @param {number} error.graphQLErrors[].statusCode - error statusCode
* @param {Array.<String>} error.graphQLErrors[].path - error path from query or mutation
* @param {string} error.graphQLErrors[].message - error message from gandalf glossary
* @param {Array.<Object>} error.graphQLErrors[].locations - error line locations
* @returns {Object} - with { code, message, statusCode, path }
*/
getError(error) {}
/**
* Check if error is an authentication error and returns a boolean
* @param {Object} error - formatted error object
* @param {string} error.message - error message
* @param {string} error.code - error code
* @param {number} error.statusCode - error statusCode
* @param {Array.<String>} error.path - error path from query or mutation
* @returns {Boolean}
*/
isAuthError(error) {}
should only be used when the APIs returns a reliable code the frontend can trust. For now, we better keep using the getError() method
/**
* Get the error object based on the gandalf error code
* @param {string} code - error unique code
* @returns {Object} - with { code, message, statusCode, path }
*/
getErrorByCode(code)
FAQs
Handler to format graphql errors into beautifully crafted user messages
The npm package @vivareal/error-glossary receives a total of 63 weekly downloads. As such, @vivareal/error-glossary popularity was classified as not popular.
We found that @vivareal/error-glossary demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 118 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.