pensoft/awt-error-formatter
最新稳定版本:v1.0.5
Composer 安装命令:
composer require pensoft/awt-error-formatter
包简介
A PHP class for formatting error payloads.
README 文档
README
A PHP class for formatting error payloads in applications. This package provides a simple and consistent way to convert error information into a structured array format, making it easier to log, display, or broadcast errors throughout your application.
Table of Contents
Features
- Consistent Error Formatting: Provides a custom format for error payloads.
- Laravel Integration: Utilizes
Illuminate\Http\Requestfor request data and accepts anyThrowableinstance for flexible error handling. - PSR-4 Autoloading: Easily integrates into your projects via Composer.
- Robust Error Handling: Supports the latest PHP error handling best practices by using the
Throwableinterface.
Requirements
- PHP 8.0 or later
- Laravel (if integrating into a Laravel project)
Installation
You can install the package via Composer. Add the following line to your project's composer.json file:
composer require pensoft/awt-error-formatter
Usage
Include in your PHP class/file
use Pensoft\AwtErrorFormatter\ErrorPayloadFormatter;
Formatting the error
// Format the error payload $errorPayload = ErrorPayloadFormatter::format( Request $request, Throwable $e, 'serviceName', 'serviceId' ); //send $errorPayload to third-party library or service
Response format
[
'service_name' => $serviceName,
'service_id' => $serviceId ?? 'no-service-id', // or cast to string/number as needed
'message' => $throwable->getMessage(), // string error message
'user_id' => $userId, // e.g., UUID or null
'timestamp' => now()->timestamp, // integer Unix timestamp
'service_type' => $serviceType, // e.g., 'backend' or 'frontend'
// "details" section with request info & error code
'details' => [
'error_type' => $errorType, // e.g., 'HTTP' or 'CRONJOB'
'uri' => $request->fullUrl(), // e.g. "https://example.com/path"
'method' => $request->method(), // e.g. "GET", "POST", etc.
'user_agent' => $request->header('User-Agent') ?? 'unknown',
'payload' => $request->all(), // entire request input as an array
'error_code' => $throwable->getCode(), // numeric or 0 if none
'stack_trace' => $throwable->getTrace(), // array full stack trace
'file_name' => $throwable->getFile(), // file path
'line_number' => $throwable->getLine(), // integer line number
],
]
统计信息
- 总下载量: 340
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-05