refactor: 规范Expection处理

This commit is contained in:
xboard
2023-12-04 20:40:49 +08:00
parent aa0fe64afe
commit 0ab7dee52d
65 changed files with 625 additions and 362 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers\V1\Staff;
use App\Exceptions\ApiException;
use App\Http\Controllers\Controller;
use App\Models\Ticket;
use App\Models\TicketMessage;
@@ -16,7 +17,7 @@ class TicketController extends Controller
$ticket = Ticket::where('id', $request->input('id'))
->first();
if (!$ticket) {
abort(500, '工单不存在');
throw new ApiException(500, '工单不存在');
}
$ticket['message'] = TicketMessage::where('ticket_id', $ticket->id)->get();
for ($i = 0; $i < count($ticket['message']); $i++) {
@@ -48,10 +49,10 @@ class TicketController extends Controller
public function reply(Request $request)
{
if (empty($request->input('id'))) {
abort(500, '参数错误');
throw new ApiException(422, '参数错误');
}
if (empty($request->input('message'))) {
abort(500, '消息不能为空');
throw new ApiException(500, '消息不能为空');
}
$ticketService = new TicketService();
$ticketService->replyByAdmin(
@@ -67,16 +68,16 @@ class TicketController extends Controller
public function close(Request $request)
{
if (empty($request->input('id'))) {
abort(500, '参数错误');
throw new ApiException(422, '参数错误');
}
$ticket = Ticket::where('id', $request->input('id'))
->first();
if (!$ticket) {
abort(500, '工单不存在');
throw new ApiException(500, '工单不存在');
}
$ticket->status = 1;
if (!$ticket->save()) {
abort(500, '关闭失败');
throw new ApiException(500, '关闭失败');
}
return response([
'data' => true