Skip to content

Repository files navigation

@nebutra/errors

Public mirror for @nebutra/errors from Nebutra/Nebutra-Sailor.

This repository is generated from the Nebutra Sailor monorepo. Package releases are cut from the monorepo and mirrored here for discovery, standalone cloning, and contribution intake.

  • Canonical source: packages/platform/errors in Nebutra/Nebutra-Sailor
  • Package registry: npm and GitHub Packages
  • Contributions: open issues or PRs here; maintainers port accepted changes back into the monorepo source package

Standardized error handling.

Installation

pnpm add @nebutra/errors

Features

  • Error Classes — Typed error hierarchy
  • HTTP Mapping — Automatic status code mapping
  • Error Codes — Machine-readable error identifiers
  • Sentry Integration — Automatic error reporting

Usage

Throw Errors

import{NotFoundError,UnauthorizedError,ValidationError,RateLimitError,}from"@nebutra/errors";thrownewNotFoundError("User not found",{userId: "123"});thrownewUnauthorizedError("Invalid token");thrownewValidationError("Email is required",{field: "email"});thrownewRateLimitError("Too many requests",{retryAfter: 60});

Error Classes

ClassHTTP StatusCode
BadRequestError400BAD_REQUEST
UnauthorizedError401UNAUTHORIZED
ForbiddenError403FORBIDDEN
NotFoundError404NOT_FOUND
ConflictError409CONFLICT
ValidationError422VALIDATION_ERROR
RateLimitError429RATE_LIMITED
InternalError500INTERNAL_ERROR

Error Handler Middleware

import{errorHandler}from"@nebutra/errors";// Express/Honoapp.use(errorHandler());// Response format:// {// "error": {// "code": "NOT_FOUND",// "message": "User not found",// "details": { "userId": "123" }// }// }

Type Guard

import{isAppError,AppError}from"@nebutra/errors";try{awaitriskyOperation();}catch(error){if(isAppError(error)){// Known error with code and statusreturnhandleKnownError(error.code,error.statusCode);}else{// Unknown errorthrownewInternalError("Unexpected error");}}

Sentry Integration

import{captureError}from"@nebutra/errors";try{awaitoperation();}catch(error){captureError(error,{user: {id: userId},tags: {feature: "checkout"},});}

Related

About

Typed error definitions and platform error contracts for Nebutra packages.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages