New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@formbricks/errors

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formbricks/errors

A helper package containing general error classes for Formbricks

0.1.0
latest
npm
Version published
Maintainers
1
Created
Source

@formbricks/errors

Error handling for @formbricks packages

Installation

npm install @formbricks/errors

Usage

import { Result, ok, err, okVoid } from "@formbricks/errors";

type CustomError = {
  code: "custom_error";
  message: string;
};

type AnotherCustomError = {
  code: "another_custom_error";
  message: string;
  anotherField: number;
};

type SuccessType = {
  id: string;
};

const test = (): Result<SuccessType, CustomError | AnotherCustomError> => {
  /* There are 4 ways to return a Result from this function */
  // return ok({ id: '123' })
  // return err({ code: 'custom_error', message: 'Custom error message' })
  // return err({ code: 'another_custom_error', message: 'Another custom error message', anotherField: 123 })
  /*
    If SuccessType is void
  */
  // return okVoid()
};

const result = test();

if (result.ok === true) {
  console.log(result.value.id); // you have full type safety here
} else if (result.error.code === "custom_error") {
  console.log(result.error.message); // you have full type safety here
} else if (result.error.code === "another_custom_error") {
  console.log(result.error.anotherField); // you have full type safety here
  console.log(result.error.message);
}

Inspiration

  • Rust Result
  • true-myth

FAQs

Package last updated on 28 Jun 2023

Did you know?

Socket

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.

Install

Related posts