Error handling for API
This commit is contained in:
parent
cf4eeb8594
commit
f8fee3e8cd
2 changed files with 4 additions and 4 deletions
|
|
@ -36,14 +36,14 @@ class AccountApiController extends BaseAPIController
|
|||
{
|
||||
if ( ! env(API_SECRET) || $request->api_secret !== env(API_SECRET)) {
|
||||
sleep(ERROR_DELAY);
|
||||
return 'Invalid secret';
|
||||
return $this->errorResponse(['message'=>'Invalid secret'],401);
|
||||
}
|
||||
|
||||
if (Auth::attempt(['email' => $request->email, 'password' => $request->password])) {
|
||||
return $this->processLogin($request);
|
||||
} else {
|
||||
sleep(ERROR_DELAY);
|
||||
return 'Invalid credentials';
|
||||
return $this->errorResponse(['message'=>'Invalid credentials'],401);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -107,13 +107,13 @@ class BaseAPIController extends Controller
|
|||
return Response::make($response, 200, $headers);
|
||||
}
|
||||
|
||||
protected function errorResponse($response)
|
||||
protected function errorResponse($response, $httpErrorCode = 400)
|
||||
{
|
||||
$error['error'] = $response;
|
||||
$error = json_encode($error, JSON_PRETTY_PRINT);
|
||||
$headers = Utils::getApiHeaders();
|
||||
|
||||
return Response::make($error, 400, $headers);
|
||||
return Response::make($error, $httpErrorCode, $headers);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue