承接 ohansyah/laravel-exception-handler 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ohansyah/laravel-exception-handler

最新稳定版本:0.1.20

Composer 安装命令:

composer require ohansyah/laravel-exception-handler

包简介

Laravel API Exception Handler with readable error messages

README 文档

README

Latest Version Total Downloads License

Introduction

Laravel API Exception Handler with readable error messages. However, this package is specifically designed to be compatible with older PHP versions and Laravel or Lumen legacy projects.

Installation

composer require ohansyah/laravel-exception-handler

Register Service Provider

$app->register(Ohansyah\ExceptionHandler\ExceptionHandlerServiceProvider::class);

Register Config

$app->configure('exception-handler');

Refreshing

composer dump-autoload

Publish Config and Lang

php artisan exception-handler:publish

Usage

use the Traits and simpy using available method resException(), resError(), resSuccess()

use Ohansyah\ExceptionHandler\Traits\ResponseTransform;

class Name 
{
    use ResponseTransform;
    ...
    resException(Exception $exception);
    resError($responseMessage, int $responseCode = 400, array $additionals = []);
    resSuccess($responseMessage, int $responseCode = 200);
    resThrowable(Throwable $throwable);
}

Global Exception Handler

// app\Exceptions\Handler.php
if (!($exception instanceof ValidationException) && !($exception instanceof NotFoundHttpException)) {
    return $this->resException($exception);
}

Sample Usage

Request:
GET {{your-base-url}}/exception-handler/error?code=500

Response:
{
    "status": "error",
    "message": "Kami telah menerima laporan bahwa layanan ini sedang mengalami gangguan. Mohon maaf atas ketidaknyamanannya dan mohon menunggu sebentar.",
    "errors": {
        "message": [
            "Kami telah menerima laporan bahwa layanan ini sedang mengalami gangguan. Mohon maaf atas ketidaknyamanannya dan mohon menunggu sebentar."
        ]
    },
    "title": "Ups!! Terjadi Kendala Teknis",
    "exception": null
}

Translation

resources\lang\en\http.php
resources\lang\id\http.php

Config

// config\exception-handler.php

'trace_exception' => env('SERVICE_TRACE_EXCEPTION', true),

License

The Laravel Exception Handler package is open-sourced software licensed under the MIT License.

统计信息

  • 总下载量: 180
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固