fix: 🚑️ Use try catch to prevent 500 errors
This commit is contained in:
parent
af5d28e2a5
commit
371a37df7a
2 changed files with 54 additions and 3 deletions
|
@ -25,7 +25,12 @@ class TicketsController extends Controller
|
|||
|
||||
public function show($ticket_id)
|
||||
{
|
||||
try {
|
||||
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
||||
} catch (Exception $e)
|
||||
{
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
}
|
||||
$ticketcomments = $ticket->ticketcomments;
|
||||
$ticketcategory = $ticket->ticketcategory;
|
||||
$server = Server::where('id', $ticket->server)->first();
|
||||
|
@ -35,7 +40,13 @@ class TicketsController extends Controller
|
|||
|
||||
public function changeStatus($ticket_id)
|
||||
{
|
||||
try {
|
||||
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
||||
} catch(Exception $e)
|
||||
{
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
}
|
||||
|
||||
if($ticket->status == "Closed"){
|
||||
$ticket->status = "Reopened";
|
||||
$ticket->save();
|
||||
|
@ -50,7 +61,14 @@ class TicketsController extends Controller
|
|||
|
||||
public function delete($ticket_id)
|
||||
{
|
||||
try {
|
||||
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
||||
} catch (Exception $e)
|
||||
{
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
|
||||
}
|
||||
|
||||
TicketComment::where('ticket_id', $ticket->id)->delete();
|
||||
$ticket->delete();
|
||||
|
||||
|
@ -60,7 +78,14 @@ class TicketsController extends Controller
|
|||
public function reply(Request $request)
|
||||
{
|
||||
$this->validate($request, ['ticketcomment' => 'required']);
|
||||
$ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail();
|
||||
try {
|
||||
$ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail();
|
||||
|
||||
}
|
||||
catch (Exception $e){
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
|
||||
}
|
||||
$ticket->status = 'Answered';
|
||||
$ticket->update();
|
||||
TicketComment::create([
|
||||
|
@ -68,7 +93,12 @@ class TicketsController extends Controller
|
|||
'user_id' => Auth::user()->id,
|
||||
'ticketcomment' => $request->input('ticketcomment'),
|
||||
]);
|
||||
try {
|
||||
$user = User::where('id', $ticket->user_id)->firstOrFail();
|
||||
} catch(Exception $e)
|
||||
{
|
||||
return redirect()->back()->with('warning', __('User not found on the server. Check on the admin database or try again later.'));
|
||||
}
|
||||
$newmessage = $request->input('ticketcomment');
|
||||
$user->notify(new ReplyNotification($ticket, $user, $newmessage));
|
||||
|
||||
|
@ -145,7 +175,13 @@ class TicketsController extends Controller
|
|||
|
||||
public function blacklistAdd(Request $request)
|
||||
{
|
||||
try {
|
||||
$user = User::where('id', $request->user_id)->first();
|
||||
}
|
||||
catch (Exception $e){
|
||||
return redirect()->back()->with('warning', __('User not found on the server. Check the admin database or try again later.'));
|
||||
|
||||
}
|
||||
$check = TicketBlacklist::where('user_id', $user->id)->first();
|
||||
if ($check) {
|
||||
$check->reason = $request->reason;
|
||||
|
|
|
@ -72,7 +72,12 @@ class TicketsController extends Controller
|
|||
|
||||
public function show($ticket_id)
|
||||
{
|
||||
try {
|
||||
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
||||
} catch (Exception $e)
|
||||
{
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
}
|
||||
$ticketcomments = $ticket->ticketcomments;
|
||||
$ticketcategory = $ticket->ticketcategory;
|
||||
$server = Server::where('id', $ticket->server)->first();
|
||||
|
@ -88,7 +93,12 @@ class TicketsController extends Controller
|
|||
return redirect()->route('ticket.index')->with('error', __("You can't reply a ticket because you're on the blacklist for a reason: '".$check->reason."', please contact the administrator"));
|
||||
}
|
||||
$this->validate($request, ['ticketcomment' => 'required']);
|
||||
try {
|
||||
$ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail();
|
||||
} catch (Exception $e)
|
||||
{
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
}
|
||||
$ticket->status = 'Client Reply';
|
||||
$ticket->update();
|
||||
$ticketcomment = TicketComment::create([
|
||||
|
@ -106,7 +116,12 @@ class TicketsController extends Controller
|
|||
}
|
||||
public function changeStatus($ticket_id)
|
||||
{
|
||||
try {
|
||||
$ticket = Ticket::where('user_id', Auth::user()->id)->where("ticket_id", $ticket_id)->firstOrFail();
|
||||
} catch (Exception $e)
|
||||
{
|
||||
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||
}
|
||||
if($ticket->status == "Closed"){
|
||||
$ticket->status = "Reopened";
|
||||
$ticket->save();
|
||||
|
|
Loading…
Reference in a new issue