当前位置:网站首页>The laravel dingo API returns a custom error message
The laravel dingo API returns a custom error message
2022-06-26 12:25:00 【Yotoai Mengtian】
laravel In the use of the dingo API after , The error message is dingo Exception class took over , The return message becomes :
To return a custom error message , You need to take over the error exception class again ( About that ...)
Method :
stay app\Providers\AppServiceProvider.php Medium boot() Method Add the following code :
app('api.exception')->register(function (\Exception $exception) {
$request = Request::capture();
return app('App\Exceptions\Handler')->render($request, $exception);
});And then in app\Exceptions\Handler.php in rewrite laravel Core package approach convertValidationExceptionToResponse(), The specific code is as follows :
public function convertValidationExceptionToResponse(ValidationException $e, $request)
{
$data = $e->validator->getMessageBag();
$msg = collect($data)->first();
if(is_array($msg)){
$msg = $msg[0];
}
return ['code'=> -1,'msg'=>$msg];
}The code in this method is for reference only , Free to play .
When you call the interface later, you will find :
, The content is customized .
边栏推荐
- Demand scale forecast and investment competitiveness analysis report of China's new material market 2022-2028
- Polarismesh series articles - concept series (I)
- What are the top ten securities companies? Is it safe to open a mobile account?
- [solved] laravel completes the scheduled job task (delayed distribution task) [execute a user-defined task at a specified time]
- HUST网络攻防实践|6_物联网设备固件安全实验|实验三 FreeRTOS-MPU 保护绕过
- How can we reach members more effectively?
- 我想知道同花顺是炒股的么?在线开户安全么?
- 2022 edition of investment analysis and "fourteenth five year plan" development prospect forecast report of China's switchgear industry
- Analysis report on dynamic research and investment planning suggestions of China's laser medical market in 2022
- NFS shared storage service installation
猜你喜欢

2、 MySQL Foundation

1、 MySQL introduction

Prospering customs through science and technology, Ronglian and Tianjin Customs jointly build a genomic database and analysis platform

Jmeter响应时间和tps监听器使用教程

Ad - update the modified PCB package to the current PCB

PHP uses laravel pay component to quickly access wechat jsapi payment (wechat official account payment)

Mqtt disconnect and reconnect

MySQL optimization - index (what is an index?)
![[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure](/img/d2/a6cbb0abe9e04c412d1f6021430528.png)
[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure

Using the methods in the repository to solve practical problems
随机推荐
大智慧哪个开户更安全,更好点
The best CMDB system
Laravel uses find_ IN_ The set() native MySQL statement accurately queries whether a special string exists in the specified string to solve the problem that like cannot be accurately matched. (resolve
Introduction to the four major FPGA manufacturers abroad
One click deployment CEPH script
2022 edition of investment analysis and "fourteenth five year plan" development prospect forecast report of China's switchgear industry
【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
Statistical genetics: Chapter 2, the concept of statistical analysis
Assembly language (7) operation instruction
Random numbers in leetcode 710 blacklist [random numbers] the leetcode path of heroding
Php+laravel5.7 use Alibaba oss+ Alibaba media to process and upload image / video files
I want to know how the top ten securities firms open accounts? Is online account opening safe?
How do consumer goods enterprises formulate membership interests?
Analysis report on China's photovoltaic inverter market prospect forecast and investment strategy recommendations in 2022
A most practical arbitrage wizard EA [2022 modified version]
Jsonarray and jsonobject of fastjson [easy to understand]
Mysql8 master-slave replication
2、 MySQL Foundation
The transformation of enterprise customers' digital assets needs to suit the case
Common problems and Thoughts on member operation management