What is @smithy/service-error-classification?
@smithy/service-error-classification is an npm package designed to help classify and handle service errors in a structured and consistent manner. It provides utilities to identify different types of errors, such as client errors, server errors, and throttling errors, and allows developers to handle these errors appropriately in their applications.
What are @smithy/service-error-classification's main functionalities?
Classify Client Errors
This feature allows you to classify whether an error is a client error (4xx status codes). The code sample demonstrates how to use the `isClientError` function to check if an error is a client error.
const { isClientError } = require('@smithy/service-error-classification');
const error = { statusCode: 400 };
if (isClientError(error)) {
console.log('This is a client error.');
}
Classify Server Errors
This feature allows you to classify whether an error is a server error (5xx status codes). The code sample demonstrates how to use the `isServerError` function to check if an error is a server error.
const { isServerError } = require('@smithy/service-error-classification');
const error = { statusCode: 500 };
if (isServerError(error)) {
console.log('This is a server error.');
}
Classify Throttling Errors
This feature allows you to classify whether an error is a throttling error (typically 429 status code). The code sample demonstrates how to use the `isThrottlingError` function to check if an error is a throttling error.
const { isThrottlingError } = require('@smithy/service-error-classification');
const error = { statusCode: 429 };
if (isThrottlingError(error)) {
console.log('This is a throttling error.');
}
Other packages similar to @smithy/service-error-classification
http-errors
The `http-errors` package is used to create HTTP errors for use in Express and other web frameworks. It provides a simple way to create error objects with HTTP status codes and messages. Unlike @smithy/service-error-classification, it focuses on creating errors rather than classifying them.
axios
The `axios` package is a popular HTTP client for making requests. It includes built-in error handling that can classify errors based on HTTP status codes. While it provides some similar functionality to @smithy/service-error-classification, its primary focus is on making HTTP requests rather than error classification.
boom
The `boom` package is used to create HTTP-friendly error objects. It is often used with the Hapi.js framework but can be used with any Node.js application. It provides utilities to create errors with specific status codes and messages, similar to @smithy/service-error-classification, but it does not focus on classifying existing errors.