Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fuel-ts/errors

Package Overview
Dependencies
Maintainers
1
Versions
2567
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fuel-ts/errors

Error class and error codes that the fuels-ts library throws

  • 0.0.0-next-20230921150310
  • npm
  • Socket score

Version published
Weekly downloads
12K
decreased by-31.74%
Maintainers
1
Weekly downloads
 
Created
Source

@fuel-ts/errors

@fuel-ts/errors is a sub-module for interacting with Fuel.

This package contains core utilities regarding throwing errors internally inside of the fuels-ts SDK.

Table of contents

  • Documentation
  • Usage
  • Contributing
  • Changelog
  • License

Documentation

See Fuels-ts Documentation

Usage

Installation

yarn add @fuel-ts/errors
# or
npm add @fuel-ts/errors

Internal usage

import { FuelError, ErrorCodes } from "@fuel-ts/error";

export function singleImport() {
  throw new FuelError(FuelError.CODES.INVALID_URL, "Invalid URL");
}

export function multipleImports() {
  throw new FuelError(ErrorCodes.INVALID_URL, "Invalid URL");
}

Test Utilities

You can use the expectToThrowFuelError test utility when asserting errors.

// can also be imported from `fuels` when using the umbrella package
import { expectToThrowFuelError } from "@fuel-ts/errors";

import { myFn } from "...";

describe('this and that' () => {
  const code = FuelError.CODES.INVALID_URL;

  it("should throw FuelError", async () => {
    const expected = new FuelError(code);
    await expectToThrowFuelError(() => myFn(), expected);
  });

  it("should throw something else", async () => {
    const expected = new FuelError(code);
    const fn = () => expectToThrowFuelError(() => myFn(), expected)
    await expect(fn).rejects.toThrow('Something else');
  });
})

External usage

import { FuelError, Provider } from "fuels";

type Locale = "PT_BR" | "BS_BA";

const currentLocale: Locale = "PT_BR";

const i18nDict = {
  PT_BR: {
    [FuelError.CODES.INVALID_URL]: "Endereço inválido",
    [FuelError.CODES.INSUFFICIENT_BALANCE]: "Saldo insuficiente",
  },
  BS_BA: {
    [FuelError.CODES.INVALID_URL]: "Nevažeća adresa",
    [FuelError.CODES.INSUFFICIENT_BALANCE]: "Nedovoljan balans",
  },
};

function translateError(e: unknown) {
  const { code } = FuelError.parse(e);
  return i18nDict[currentLocale][code];
}

function main() {
  try {
    const p = new Provider("0004:tƨoʜlɒɔol//:qttʜ");
    console.log(p);
  } catch (e) {
    const prettyError = translateError(e);
    console.log({ prettyError });
  }
);

Contributing

In order to contribute to @fuel-ts/errors, please see the main fuels-ts monorepo.

Changelog

The @fuel-ts/errors changelog can be found at CHANGELOG.

License

The primary license for @fuel-ts/errors is Apache 2.0, see LICENSE.

FAQs

Package last updated on 21 Sep 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

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