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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@devua-lab/error-serialization

v1.0.6

Published

A lightweight, highly extensible TypeScript library for standardized error serialization. It provides a unified pipeline to transform any error—from Zod validation issues and Axios HTTP failures to native JavaScript errors and raw strings—into a consisten

Downloads

18

Readme

@devua-lab/error-serialization

A lightweight, highly extensible TypeScript library for standardized error serialization. It provides a unified pipeline to transform any error—from Zod validation issues and Axios HTTP failures to native JavaScript errors and raw strings—into a consistent, strictly typed response format.


📑 Table of Contents

  1. Features
  2. Installation
  3. Quick Start
  4. Usage Guide
  5. Standard Response Format
  6. Standard Plugins
  7. Priority System

✨ Features

  • 🎯 Universal Standardization: Regardless of the error source, the output always follows the same predictable interface.
  • 🏗️ Structured Validation Mapping: Advanced transformation of Zod issues into flat keys or deep object hierarchies.
  • 🌐 Generic API Extraction: Smart parsing of backend error messages and codes from HTTP responses.
  • 🚀 Priority-Based Execution: Automatically selects the most appropriate handler.
  • 🔔 Real-time Subscriptions: Simple callback system for global error monitoring.
  • 🛡️ Preservation of Context: Access low-level details (like Axios request configs) via the preserved original error.

📦 Installation

npm install @devua-lab/error-serialization

Peer Dependencies

This library requires axios and zod to be installed in your project as peer dependencies:

npm install axios zod

🚀 Quick Start

import { ErrorSerializer, ZodErrorPlugin, AxiosErrorPlugin } from '@devua-lab/error-serialization';

// 1. Initialize
const serializer = new ErrorSerializer();

// 2. Register plugins
serializer
  .register(new AxiosErrorPlugin())
  .register(new ZodErrorPlugin({ structure: 'nested' }));

// 3. Use in your application
try {
  await api.post('/login', data);
} catch (error) {
  const result = serializer.process(error);
  console.log(result.global); // "Invalid credentials"
  console.log(result.status); // 401
}

🛠 Usage Guide

1. Setup & Registration

Create a central error utility in your app to reuse the serializer instance. Register plugins in any order; the library will sort them by internal priority.

// error-utility.ts
import { 
  ErrorSerializer, 
  ZodErrorPlugin, 
  AxiosErrorPlugin, 
  StandardErrorPlugin 
} from '@devua-lab/error-serialization';

export const errorSerializer = new ErrorSerializer();

errorSerializer
  .register(new StandardErrorPlugin())
  .register(new AxiosErrorPlugin())
  .register(new ZodErrorPlugin({ 
    structure: 'flat', 
    messageFormat: 'string' 
  }));

2. Processing Errors

Simply wrap your logic in a try/catch block and pass the caught error to the process method.

import { errorSerializer } from './error-utility';

async function handleSubmit(formData: any) {
  try {
    const validated = schema.parse(formData);
    await userService.create(validated);
  } catch (err) {
    const error = errorSerializer.process(err);

    if (error.status === 422) {
      // Handle validation errors in UI
      setFormErrors(error.validation);
    } else {
      // Show global notification
      toast.error(error.global || "Something went wrong");
    }
  }
}

3. Global Subscriptions

Use subscriptions to automate logging or reporting without cluttering your business logic.

errorSerializer.subscribe((context) => {
  // Report critical errors to Sentry
  if (context.status && context.status >= 500) {
    Sentry.captureException(context.error);
  }

  // Analytics for specific error codes
  if (context.code?.includes('AUTH_EXPIRED')) {
    analytics.track('Session Timeout');
  }
});

🏗 Standard Response Format

The process method always returns an AppErrorResponse object:

{
  metadata: {
    plugin: string;    // Plugin name (e.g., "ZodErrorPlugin" or "ErrorSerializer" for fallbacks)
    priority: number;  // Level (2: Zod, 1: Axios, 0: Standard, -1: Fallback)
  },
  error: unknown;      // The ORIGINAL error object
  global?: string;     // Main human-readable message
  code?: string[];     // Array of error codes (e.g., ["102", "CONFLICT"])
  status?: number;     // Numeric status code (e.g., 422, 500, or 0)
  validation?: {       // Object with field-level errors
    [key: string]: any;
  }
}

⚙️ Priority System

| Plugin | Priority | Matching Criteria | | :--- | :--- | :--- | | ZodErrorPlugin | 2 | instanceof ZodError | | AxiosErrorPlugin | 1 | axios.isAxiosError(error) | | StandardErrorPlugin | 0 | instanceof Error | | ErrorSerializer | -1 | Fallback for raw strings, numbers, or null |