
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
format-errors-pg
Advanced tools
Use this application to protect people from technical details by abstracting Node + PG errors (more specifically the error.stack messages returned from RESTFUL API calls.)
Make sure you are CD'd into the same level of your application's package.json file.
In the CLI run npm i format-errors-pg
const formatErrorPG = require("format-errors-pg");
router.post("/register", async (req, res) => {
const { name, password } = req.body;
const newUser = {
name,
password
}
try {
await database.query("INSERT into USERS ( name, password ) VALUES ( $1, $2 )", [
name,
password
]);
return res.status(200).json({newUser})
} catch (error) {
res.status(500).json({ error: formatPGErrors(error) });
}
});
res.status(500).json({ error: formatPGErrors(error) });
Note that the .stack property is somewhat hidden on the error object that is sent back from PG. However, it IS there.
That is where the function should be used, with 500 errors inside of catch blocks.
It works with promises as well if you do not want/can-not use async and await for some reason :).
Inside of the Postman application I made a HTTP POST request to my application's end-point, and it returned the following output:
{
"error": "duplicate key value violates unique constraint
\"users_name_key\"",
}
As you can see the error message is pretty clear. We are dealing with a user's name duplication error.
users at the column entitled name, and then fill in the rest of it by the other parts of the message.More practice!!
{
"error": "duplicate key value violates unique constraint
\"users_email_key\""
}
FED sees this and will probably think hmm, we probably have a duplicate email address in use.
BED/full-stack/genius-wizard might think error at table users at column email, and then fill in the rest of it by the other parts of the message.
If you are more experienced with Node + PG and the BE in general then you might be thinking "this is already in the error message". I say yes, it IS in the error message. However, this is a message that a front-end developer can easily understand without be scared off by a giant wall of error text. It removes the rest of the message which contains all the file paths that are stored in the error stack.
FAQs
Use this application to protect people from technical details by abstracting Node + PG errors (more specifically the error.stack messages returned from RESTFUL API calls.)
We found that format-errors-pg 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
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.