Download the PHP package andrewdyer/json-error-handler without Composer

On this page you can find all versions of the php package andrewdyer/json-error-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package json-error-handler

JSON Error Handler

A structured JSON error handler for Slim Framework applications that maps exceptions to typed, consistent error payloads.

Latest Stable Version Total Downloads License PHP Version Require

Introduction

This library extends Slim Framework's built-in error handling to intercept exceptions and transform them into well-formed JSON responses with appropriate HTTP status codes. It supports optional error detail exposure for debug environments and integrates directly with Slim's error middleware. For shutdown handling workflows, it can be paired with andrewdyer/shutdown-handler to keep unhandled error responses consistent.

Prerequisites

Installation

Getting Started

1. Create the application

2. Add error middleware

Add the error middleware and set JsonErrorHandler as the default handler. The $displayErrorDetails flag controls whether exception messages are included in responses — this should be false in production:

Note: A PSR-3 logger can be passed as the third argument to enable error logging. Monolog is a popular choice for this.

By default, payloads are encoded with JSON_PRETTY_PRINT. Custom flags can be passed as the fourth constructor argument:

Note that JSON_THROW_ON_ERROR is always masked out internally to prevent encoding failures from cascading during error handling.

3. Register routes

Register routes to handle incoming requests:

4. Run the application

Start the application to begin handling incoming HTTP requests:

Usage

Once the handler is registered, Slim will route exceptions through JsonErrorHandler and return structured JSON error responses.

Successful request

Response: 200 OK

Error request

Response: 404 Not Found

Advanced Usage

Shutdown handler integration

For complete fatal error coverage — including errors that occur outside of Slim's request lifecycle — JsonErrorHandler can be integrated with andrewdyer/shutdown-handler:

Wrap JsonErrorHandler in a CallableErrorResponder and register a ShutdownHandler before running the application:

Refer to the shutdown-handler documentation for full details on implementing a response emitter.

License

Licensed under the MIT license and is free for private or commercial projects.


All versions of json-error-handler with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
andrewdyer/actions Version ^1.3
psr/http-factory Version ^1.1
psr/http-message Version ^1.1 || ^2.0
psr/log Version ^1.1 || ^2.0 || ^3.0
slim/slim Version ^4.15
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package andrewdyer/json-error-handler contains the following files

Loading the files please wait ...