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

@ledgerhq/errors

Package Overview
Dependencies
Maintainers
7
Versions
232
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ledgerhq/errors

Ledger common errors

  • 6.18.0-nightly.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
7
Created

What is @ledgerhq/errors?

@ledgerhq/errors is an npm package designed to handle and manage errors specifically for Ledger hardware wallet applications. It provides a structured way to define, throw, and catch errors, making error handling more consistent and easier to manage.

What are @ledgerhq/errors's main functionalities?

Custom Error Definitions

This feature allows you to define custom error classes that extend the built-in TransportError class. This makes it easier to create specific error types for different scenarios.

const { TransportError, StatusCodes } = require('@ledgerhq/errors');

class MyCustomError extends TransportError {
  constructor(message) {
    super(message, StatusCodes.UNKNOWN_ERROR);
    this.name = 'MyCustomError';
  }
}

try {
  throw new MyCustomError('Something went wrong');
} catch (error) {
  console.error(error.name); // MyCustomError
  console.error(error.message); // Something went wrong
  console.error(error.statusCode); // UNKNOWN_ERROR
}

Error Handling

This feature demonstrates how to handle errors thrown by operations, specifically checking if the error is an instance of TransportError and logging the appropriate message and status code.

const { TransportError, StatusCodes } = require('@ledgerhq/errors');

function performOperation() {
  throw new TransportError('Operation failed', StatusCodes.CONDITIONS_OF_USE_NOT_SATISFIED);
}

try {
  performOperation();
} catch (error) {
  if (error instanceof TransportError) {
    console.error(`Error: ${error.message}, Status Code: ${error.statusCode}`);
  } else {
    console.error('An unknown error occurred');
  }
}

Predefined Status Codes

The package provides a set of predefined status codes that can be used to standardize error handling across different parts of your application.

const { StatusCodes } = require('@ledgerhq/errors');

console.log(StatusCodes.CONDITIONS_OF_USE_NOT_SATISFIED); // 0x6985
console.log(StatusCodes.INS_NOT_SUPPORTED); // 0x6D00

Other packages similar to @ledgerhq/errors

Keywords

FAQs

Package last updated on 09 Jul 2024

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