Socket
Socket
Sign inDemoInstall

erreur

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

erreur - npm Package Compare versions

Comparing version 3.0.0-11 to 3.0.0-12

2

package.json
{
"name": "erreur",
"version": "3.0.0-11",
"version": "3.0.0-12",
"description": "Type safe custom errors",

@@ -5,0 +5,0 @@ "keywords": [

@@ -16,6 +16,6 @@ # 🛑 Erreur

```ts
import { createKey, Erreur } from 'erreur';
import { createErreurType, Erreur } from 'erreur';
// Create a new key
const StatusCodeKey = createKey<number>({ name: 'StatusCode' });
// Create a new type
const HttpErrorType = createErreurType<number>({ name: 'StatusCode' });

@@ -26,6 +26,8 @@ // Create a new Erreur

// Add data to the Erreur
const errWithStatusCode = err.with(StatusCodeKey.Provider(500));
const errWithStatusCode = HttpErrorType.extends(err, 500);
// Get data from the Erreur
const statusCode = errWithStatusCode.get(StatusCodeKey.Consumer);
const statusCode = errWithStatusCode.get(HttpErrorType.Consumer);
expect(statusCode).toBe(500);
```

@@ -90,18 +92,2 @@

### Dynamic message
For a more advanced usage, you can use the `Erreur.GetMessageKey` (or `erreur.withGetMessage`) key to provide a function that will be called when the message is accessed, this function will receive the `Erreur` instance as an argument:
```ts
const StatusCodeKey = createKey<number>({ name: 'StatusCode', defaultValue: 500 });
const HttpErreur = Erreur.create().withGetMessage((err) => {
return `Something went wrong: ${err.get(StatusCodeKey.Consumer)}`;
});
const NotFoundErreur = HttpErreur.with(StatusCodeKey.Provider(404));
console.log(NotFoundErreur.message); // Something went wrong: 404
```
## Recipes

@@ -119,3 +105,3 @@

const FetchErrorKey = createKey<FetchError>({ name: 'FetchError' });
const FetchErrorType = createErrorType<FetchError>({ name: 'FetchError' });
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc