ap-lib/error-node

A simple and lightweight PHP library for handling structured error messages, useful for validation, data processing, and API responses

dev-main 2025-03-04 04:45 UTC

This package is auto-updated.

Last update: 2025-03-04 04:45:13 UTC


README

MIT License

A simple and lightweight PHP library for handling structured error messages, useful for validation, data processing, and API responses.

Installation

composer require ap-lib/error-node

Features

  • Structured error representation
  • Easy instantiation of single or multiple errors
  • Throwable error handling
  • Simple and extensible design

Requirements

  • PHP 8.3 or higher

Getting started

Basic usage

use AP\ErrorNode\Error;
use AP\ErrorNode\Errors;
use AP\ErrorNode\ThrowableErrors;

// Creating a single error
$error = new Error("Invalid input", ["user", "email"]);

// Creating multiple errors
$errors = new Errors([
    new Error("Field is required", ["user", "name"]),
    new Error("Invalid format", ["user", "email"]),
]);

// Handling errors
if (!empty($errors->getErrors())) {
    throw $errors->getNodeErrorsThrowable();
}