npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@payello-sdk/errors

v1.20240420.17

Published

The `@payello-sdk/errors` package provides a comprehensive set of standardized error types designed to handle different error scenarios encountered within the Payello SDK ecosystem.

Downloads

14

Readme

@payello-sdk/errors

The @payello-sdk/errors package provides a comprehensive set of standardized error types designed to handle different error scenarios encountered within the Payello SDK ecosystem.

This package facilitates the process of identifying, categorizing, and handling errors in a systematic way across various operations, authentication processes, request handling, and service interactions.

This package is actively used by Payello, a financial services platform committed to advancing innovation in the financial industry. Payello champions open-source contributions, harnessing these technologies to enhance its platform and client projects.

Features

  • Authentication Errors: Handle authentication-related issues, such as expired tokens, revoked access, or missing authentication credentials.
  • Operation Errors: Manage errors that occur during operational processes like transaction declines, account restrictions, or compliance violations.
  • Request Errors: Address errors arising from API requests, including invalid parameters, unsupported content types, or encryption requirements.
  • Service Errors: Deal with errors related to service availability, dependency failures, or maintenance windows.
  • API Response Generation: Create API Responses automatically from thrown errors.

Getting Started

To start using the @payello-sdk/errors package, first install it via npm:

npm install @payello-sdk/errors

or using yarn:

yarn add @payello-sdk/errors

Usage

After installation, you can import any specific error class based on the scenario you're handling. Here's an example of how to use an authentication error:

import { AuthExpiredError } from "@payello-sdk/errors"

function authenticateUser(token) {
	if (isTokenExpired(token)) {
		throw new AuthExpiredError({ expired_at: token.expire_at })
		//                           ^ hints
	}
	// Proceed with authentication
}

Similarly, you can handle different types of errors based on the operation, request, or service scenario you're dealing with.

API Response Generation

The PayelloError class extends the native Error class, adding statusCode and errorDetails properties that are pivotal for generating API response errors. Here’s a breakdown of its functionality:

  • Status Code Mapping: Depending on the type of error (ErrorType), a corresponding HTTP status code is automatically defined.
  • Error Details: The error details (errorDetails property) include important information about the error, such as the error type and message, which helps in diagnosing and rectifying the issue.
  • Error Hints: Enhance error messages with "hints" in the errorDetails, offering users actionable suggestions, such as expected input formats or links to relevant documentation.
  • toResponse: The toResponse method allows you to generate a structured response containing the error details, along with the appropriate HTTP status code. This method facilitates easy integration with web frameworks that support or require error handling through Fetch responses. You can pass a responseFactory object that implements the ResponseFactory interface to customize the response format. By default it will return a Fetch response.

API Response Example

This snippet below demonstrates how a PayelloError can be caught and how to use the generated response. The catch block checks if the error is an instance of PayelloError and uses its toResponse method to return a Fetch API response (the default).

import { InvalidBodyError, PayelloError } from '@payello-sdk/errors';

try {
    // Throw one of the errors
    throw new InvalidBodyError();
} catch (error) {
    // Check if it's a PayelloError
    if (error instanceof PayelloError) {
        // Return the generated response
        return error.toResponse();
    }
    // If not handle other types of errors or pass to a generic error handler
    console.error(error);
}

Error Categories

Authentication Errors

  • AuthError
  • AuthErrorCode
  • AuthExpiredError
  • AuthInvalidError
  • AuthMissingError
  • AuthRevokedError
  • PermissionError
  • SecurityError
  • UnauthorizedIPError
  • UserLockedError

Operation Errors

  • OperationError
  • AccountRestrictedError
  • ComplianceViolationError
  • DuplicateTransactionError
  • FraudDetectedError
  • IncompatibleError
  • InsufficientResourcesError
  • InvalidCurrencyError
  • InvalidDetailsError
  • OperationBlockedError
  • QuotaError
  • RateLimitError
  • StateConflictError
  • TransactionDeclinedError
  • UnsupportedOperationError

Request Errors

  • RequestError
  • EncryptionRequiredError
  • InvalidBodyError
  • InvalidContentTypeError
  • InvalidMethodError
  • ParamFormatError
  • ParamMissingError
  • ParamTypeError
  • ResourceNotFoundError

Service Errors

  • ServiceError
  • DependencyFailureError
  • InternalError
  • MaintenanceError
  • ServiceUnavailableError
  • TimeoutError
  • UpstreamError
  • UpstreamMaintenanceError
  • UpstreamUnavailableError