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

restify-errors

Package Overview
Dependencies
Maintainers
7
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restify-errors

Collection of Error objects shared across restify components.

  • 8.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
171K
decreased by-10.48%
Maintainers
7
Weekly downloads
 
Created

What is restify-errors?

The restify-errors package provides a set of HTTP and REST error classes for use with the Restify framework. It simplifies error handling by providing a consistent way to create and manage errors in your Restify applications.

What are restify-errors's main functionalities?

Creating Standard HTTP Errors

This feature allows you to create standard HTTP errors like 404 Not Found, 500 Internal Server Error, etc. The code sample demonstrates creating a 404 Not Found error.

const restifyErrors = require('restify-errors');
const error = new restifyErrors.NotFoundError('Resource not found');
console.log(error);

Custom Error Classes

You can create custom error classes that extend the base HttpError class. The code sample shows how to create a custom error with a 418 status code.

const restifyErrors = require('restify-errors');
class CustomError extends restifyErrors.HttpError {
  constructor(message) {
    super({ statusCode: 418, message });
    this.name = 'CustomError';
  }
}
const error = new CustomError('I am a teapot');
console.log(error);

Error Serialization

Errors can be serialized to JSON for easy transmission over HTTP. The code sample demonstrates serializing an InternalServerError to JSON.

const restifyErrors = require('restify-errors');
const error = new restifyErrors.InternalServerError('Something went wrong');
const serializedError = JSON.stringify(error.toJSON());
console.log(serializedError);

Other packages similar to restify-errors

Keywords

FAQs

Package last updated on 13 Dec 2019

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