Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@jetti/jetti.problem
Advanced tools
Readme
Library for propagating 7807 errors, based on api-problem (https://github.com/ahmadnassri/node-api-problem). You'll need to import into the repository you want to trigger the errors form. This should replace all throw new Error()
calls with the following code:
import { ApiProblem } from '@jetti/jetti.problem';
throw new ApiProblem({
code: 'api.channels.process_sale.missing',
details: {
externalId,
},
});
For errors related to Sequelize models:
import { InstanceProblem } from '@jetti/jetti.problem';
const instanceError = new InstanceProblem({
instance,
action: 'export',
// or module.filename,
// Optional
content: 'empty,'
// Optional
details: {
externalId: '1234',
},
});
For errors related to integrations:
import { IntegrationProblem } from '@jetti/jetti.problem';
const integrationError = new IntegrationProblem({
integration: 'wooCommerce',
resource: 'orders',
action: 'import',
context: 'no_attributes',
details: {
externalId: '1234',
},
});
Although not a requirement, you can create a Contentful entry under the error
content type, with a corresponding code. This will then merge the title into the error message. The details array should contain any useful details about the error, in alignment with the 7807 spec.
You'll need to add an .env file for the build process:
CONTENTFUL_SPACE={{space}}
CONTENTFUL_TOKEN={{token}}
For convenience, it's also possible to wrap class methods to capture any unhandled exceptions. This will coerce any errors into the problem 7807 standard.
class Postmen {
// Or CatchApi()
@CatchIntegration({ resource: 'rates', ...options })
rates() {
throw new Error('Something unexpected');
}
}
Often, integrations will pass back errors in different formats. For example, have an errors
array, or maybe a meta
object that lists the errors. It's useful to get these varying error messages and consolidate down to a common format. For a jetti.problem, this will be detailed in the details
object. To handle this conversion, the calling / catcher of the problem should pass a parser
function that takes a given request response and allows mapping map to a common format.
const throwMe = {
variant: {
message: 'not found!',
},
};
const parser = ({ response: toPrase }) => ({
messages: Object.entries(toPrase).reduce((obj, [code, { message }]) => ({
[code]: [message],
...obj,
}), {}),
});
@IntegrationCatch({ parser })
This will take a request object, map the data and pass back in a format below. It should return an array of messages, in the format below.
{
"type": "https://problems.jetti.io/details#integrations.postmen.rates.rates",
"title": "integrations.postmen.rates.rates",
"status": 418,
"details": {
"message": "Response code 418 (I'm a Teapot)",
"response": {
"variant": {
"message": "not found!"
}
},
"messages": {
"variant": ["not found!"]
},
"integration": "postmen",
"resource": "rates",
"context": "rates"
}
}
If there is no "code" and the integration just returns an array of messages, you should use "all",
...
"messages": {
"all": ["not found!"]
},
...
FAQs
Error handling for Jetti
The npm package @jetti/jetti.problem receives a total of 3,360 weekly downloads. As such, @jetti/jetti.problem popularity was classified as popular.
We found that @jetti/jetti.problem demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.