Search by

christianjbrown / user-friendly-exception

christianjbrown

A tiny PHP library providing a UserFriendlyException whose message is safe to display directly to end users.

Package info

github.com/christianjbrown/user-friendly-exception-php

pkg:composer/christianjbrown/user-friendly-exception

Statistics

Installs: 115

Dependents: 1

Suggesters: 0

Stars: 0

v1.0.1 2026-10-01 11:29 UTC

This package is auto-updated.

Last update: 2026-10-01 13:33:42 UTC


README

CI Coverage Packagist License PHP

This is an extremely simple PHP library for a reusable UserFriendlyException class.

Using UserFriendlyException indicates that the $message passed is safe to and clear enough to be bubbled up to the end user.

✔️ Prerequisites

💡 If you're on MacOS and have Homebrew, PHP and Composer will install with brew install composer.

🏗️ Installation

For your composer-enabled project:

composer require christianjbrown/user-friendly-exception

💻 Usage

Throwing the exception after catching a non-user-friendly exception.

use ChristianBrown\UserFriendlyException\UserFriendlyException;
use RuntimeException;

try {
  // ...
  // Technical issue here
  // ...
} catch (RuntimeException $e) {
  throw new UserFriendlyException('We encountered a technical issue. Please try again later', 0, $e);
}

Later passing the contents of UserFriendlyException directly to the end users

use ChristianBrown\UserFriendlyException\UserFriendlyExceptionInterface;
use Throwable;

$app = new Application();
try {
  $responseText = $app->run();
  $response = new Response($responseText, 200);
} catch (UserFriendlyExceptionInterface $e) {
  $response = new Response($e->getMessage(), $e->getCode() ?: 500);
} catch (Throwable $e) {
  $response = new Response('An unknown error occurred, try again later', 500);
}

return $response;

📝 Changelog

Notable changes in each release are listed in CHANGELOG.md.

📄 License

Released under the MIT License.