An open API service indexing awesome lists of open source software.

https://github.com/pt-dot/laravel-error-message

Laravel simple error message display from exception
https://github.com/pt-dot/laravel-error-message

exception-reporting laravel package php

Last synced: about 1 month ago
JSON representation

Laravel simple error message display from exception

Awesome Lists containing this project

README

          

# Laravel Error Message Displayer

Sometimes in development mode, you want to display exception message to know what happened to your web application. But in production environment, you may want to display general message instead of direct exception message. Laravel error message displayer is a package for displaying exception message or trace string based on `APP_DEBUG` condition.

## Requirements
+ php 7.0+
+ Laravel 5.5+

## Installation

Install package through composer.

```bash
composer require ptdot/errormessage
```

Next, if using Laravel under 5.5, include the service provider and Facade within your `config/app.php` file.

```php
'providers' => [
Ptdot\ErrorMessage\ErrorMessageServiceProvider::class,
],

'aliases' => [
'ErrorMessage' => Ptdot\ErrorMessage\ErrorMessage::class,
]
```

Since Laravel 5.5+ is using Package Discovery, there is no need manually insert service provider and facade inside your `app.php`.

## Configuration

Publish config using command:

```bash
php artisan vendor:publish
```

Set your default error message in `config/errormessage.php`.

## Basic Usage

You may use this package to handle exception display through your REST API or flash message.
```php
json([
'errors' => ErrorMessage::displayExceptionMessage($exception)
], 500);
}
```

If you want to debug and need display `traceAsString` option, you may call `traceAsString()` method:

```php
// you may need traceAsString option enabled using this way:
return response()->json([
'errors' => ErrorMessage::traceAsString()->displayExceptionMessage($exception)
], 500);
```

Want to override default message? Don't worry this package is able to do that.

```php
// Need to override exception message? Don't worry
return response()->json([
'errors' => ErrorMessage::displayExceptionMessage($exception, 'exception message will be overrided with this')
], 500);
```

## Contributing

Feel free to report an issue or merge request if you want to help this package become better and useful.