Socket
Socket
Sign inDemoInstall

defekt

Package Overview
Dependencies
Maintainers
5
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defekt - npm Package Compare versions

Comparing version 7.1.2 to 7.2.0

2

build/lib/Result.d.ts
interface ResultBase<TValue, TError extends Error> {
hasError: () => this is ResultError<TValue, TError>;
hasValue: () => this is ResultValue<TValue, TError>;
unwrapOrThrow: () => TValue;
unwrapOrThrow: (errorTransformer?: (err: TError) => Error) => TValue;
unwrapOrElse: (handleError: (error: Error) => TValue) => TValue;

@@ -6,0 +6,0 @@ unwrapOrDefault: (defaultValue: TValue) => TValue;

@@ -12,3 +12,6 @@ "use strict";

},
unwrapOrThrow() {
unwrapOrThrow(errorTransformer) {
if (errorTransformer) {
throw errorTransformer(err);
}
// eslint-disable-next-line @typescript-eslint/no-throw-literal

@@ -15,0 +18,0 @@ throw err;

@@ -0,1 +1,8 @@

# [7.2.0](https://github.com/thenativeweb/defekt/compare/7.1.2...7.2.0) (2021-05-25)
### Features
* Add callback to unwrapOrThrow to transform errors. ([#314](https://github.com/thenativeweb/defekt/issues/314)) ([c7512d2](https://github.com/thenativeweb/defekt/commit/c7512d2c87ed3863baf996b5f5dbc8645232563f))
## [7.1.2](https://github.com/thenativeweb/defekt/compare/7.1.1...7.1.2) (2021-05-18)

@@ -2,0 +9,0 @@

@@ -5,3 +5,3 @@ interface ResultBase<TValue, TError extends Error> {

unwrapOrThrow: () => TValue;
unwrapOrThrow: (errorTransformer?: (err: TError) => Error) => TValue;
unwrapOrElse: (handleError: (error: Error) => TValue) => TValue;

@@ -23,3 +23,6 @@ unwrapOrDefault: (defaultValue: TValue) => TValue;

},
unwrapOrThrow (): never {
unwrapOrThrow (errorTransformer?: (err: TError) => Error): never {
if (errorTransformer) {
throw errorTransformer(err);
}
// eslint-disable-next-line @typescript-eslint/no-throw-literal

@@ -26,0 +29,0 @@ throw err;

{
"name": "defekt",
"version": "7.1.2",
"version": "7.2.0",
"description": "defekt is custom errors made simple.",

@@ -35,5 +35,5 @@ "contributors": [

"devDependencies": {
"assertthat": "6.0.1",
"roboter": "11.6.42",
"semantic-release-configuration": "2.0.0"
"assertthat": "6.2.1",
"roboter": "11.6.48",
"semantic-release-configuration": "2.0.1"
},

@@ -40,0 +40,0 @@ "repository": {

@@ -253,2 +253,8 @@ # defekt

// If you want to transform the error to add additional information, or to
// fulfill a more general error type, you can also pass a callback:
const token = validateToken('a token').unwrapOrThrow(
err => new BroaderError({ message: 'Something went wrong', cause: err })
);
// If you want to handle errors by returning a conditional default

@@ -255,0 +261,0 @@ // value, you can use `unwrapOrElse` to supply a handler:

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