Socket
Socket
Sign inDemoInstall

@feathersjs/errors

Package Overview
Dependencies
0
Maintainers
4
Versions
112
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@feathersjs/errors


Version published
Maintainers
4
Created

Package description

What is @feathersjs/errors?

@feathersjs/errors is a package that provides a set of common error classes and utilities for handling errors in FeathersJS applications. It helps in creating consistent error responses and simplifies error handling in your application.

What are @feathersjs/errors's main functionalities?

Creating Custom Errors

This feature allows you to create and throw custom errors like NotFound, BadRequest, etc., which are predefined in the package. This helps in maintaining consistency in error handling across your application.

const { NotFound } = require('@feathersjs/errors');

// Throw a NotFound error
throw new NotFound('User not found');

Error Handling Middleware

This feature provides middleware for handling errors in an Express application. It checks if the error is an instance of GeneralError and sends a structured JSON response with error details.

const { GeneralError } = require('@feathersjs/errors');

// Express error handling middleware
app.use((err, req, res, next) => {
  if (err instanceof GeneralError) {
    res.status(err.code).json({
      name: err.name,
      message: err.message,
      code: err.code,
      className: err.className,
      data: err.data,
      errors: err.errors
    });
  } else {
    next(err);
  }
});

Custom Error Classes

This feature allows you to create your own custom error classes by extending the FeathersError class. This is useful for defining application-specific errors with custom properties.

const { FeathersError } = require('@feathersjs/errors');

class CustomError extends FeathersError {
  constructor(message, data) {
    super(message, 'custom-error', 400, 'CustomError', data);
  }
}

// Throw a CustomError
throw new CustomError('This is a custom error', { additional: 'data' });

Other packages similar to @feathersjs/errors

Changelog

Source

5.0.0-pre.22 (2022-05-24)

Bug Fixes

  • schema: Allows resolveData with different resolvers based on method (#2644) (be71fa2)

Readme

Source

@feathersjs/errors

CI Download Status Discord

Common error types for feathers apps

Installation

npm install @feathersjs/errors --save

Documentation

Refer to the Feathers errors API documentation for more details.

License

Copyright (c) 2022 Feathers contributors

Licensed under the MIT license.

Keywords

FAQs

Last updated on 24 May 2022

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc