Skip to content

Commit

Permalink
🐛 Catch error when wrong datatype is given in request (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu authored Sep 30, 2021
1 parent 3fdbd0a commit 2a1fc59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/Http/Controllers/FrontendStatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,22 @@ public function getGlobalDashboard(): Renderable {
]);
}

/**
* @param Request $request
* @todo Is this api? Because of JsonReponse. But if yes: Why it does an Redirect?
* @return JsonResponse|RedirectResponse
*/
public function DeleteStatus(Request $request): JsonResponse|RedirectResponse {
try {
StatusBackend::DeleteStatus(Auth::user(), $request['statusId']);
if(!is_numeric($request['statusId'])) {
return redirect()->back()->with('error', __('error.bad-request'));
}
StatusBackend::DeleteStatus(Auth::user(), (int)$request['statusId']);
} catch (PermissionException | ModelNotFoundException) {
return redirect()->back()->with('error', __('controller.status.not-permitted'));
}

return response()->json(['message' => __('controller.status.delete-ok')], 200);
return response()->json(['message' => __('controller.status.delete-ok')]);
}

public function EditStatus(Request $request): JsonResponse|RedirectResponse {
Expand Down
1 change: 1 addition & 0 deletions resources/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"dates.Wednesday": "Mittwoch",
"dateformat.with-weekday": "dddd, DD. MMMM YYYY",
"dateformat.month-and-year": "MMMM YYYY",
"error.bad-request": "Die Anfrage ist ungültig.",
"events.header": "Veranstaltung: :name",
"events.name": "Name",
"events.hashtag": "Hashtag",
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"controller.user.follow-request-ok": "Requested follow.",
"controller.user.password-changed-ok": "Password changed.",
"controller.user.password-wrong": "Password wrong.",
"error.bad-request": "The request is invalid.",
"dates.-on-": " on ",
"dates.decimal_point": ".",
"dates.thousands_sep": ",",
Expand Down

0 comments on commit 2a1fc59

Please sign in to comment.