Handle missing 2FAccount when updating

This commit is contained in:
Bubka 2020-01-10 08:35:15 +01:00
parent aaab76b7d3
commit e9ecbbe057
2 changed files with 17 additions and 3 deletions

View File

@ -95,7 +95,7 @@ public function generateTOTP(TwoFAccount $twofaccount)
* @param \App\TwoFAccount $twofaccount
* @return \Illuminate\Http\Response
*/
public function update(Request $request, TwoFAccount $twofaccount)
public function update(Request $request, $id)
{
$validator = Validator::make($request->all(), [
@ -106,9 +106,20 @@ public function update(Request $request, TwoFAccount $twofaccount)
return response()->json(['error' => $validator->errors()], 400);
}
$twofaccount->update($request->all());
return response()->json($twofaccount, 200);
try {
$twofaccount = TwoFAccount::FindOrFail($id);
$twofaccount->update($request->all());
return response()->json($twofaccount, 200);
}
catch (\Exception $e) {
return response()->json(['error'=>'not found'], 404);
}
}

View File

@ -119,6 +119,9 @@
if (error.response.status === 400) {
this.errors = error.response.data.error
}
else if (error.response.status === 404) {
this.$router.push({name: '404' });
}
});
},