Handle missing 2FAccount when deleting

This commit is contained in:
Bubka
2020-01-10 00:22:45 +01:00
parent 7b5ac91796
commit aaab76b7d3
2 changed files with 23 additions and 12 deletions

View File

@ -118,18 +118,29 @@ class TwoFAccountController extends Controller
* @param \App\TwoFAccount $twofaccount
* @return \Illuminate\Http\Response
*/
public function destroy(TwoFAccount $twofaccount)
public function destroy($id)
{
// delete icon
$storedIcon = 'public/icons/' . $twofaccount->icon;
try {
$twofaccount = TwoFAccount::FindOrFail($id);
// delete icon
$storedIcon = 'public/icons/' . $twofaccount->icon;
if( Storage::exists($storedIcon) ) {
Storage::delete($storedIcon);
}
$twofaccount->delete();
return response()->json(null, 204);
if( Storage::exists($storedIcon) ) {
Storage::delete($storedIcon);
}
catch (\Exception $e) {
$twofaccount->delete();
return response()->json('already gone', 404);
return response()->json(null, 204);
}
}
}