mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
API error reporting (#1276)
* fix env variable * update routes * Improve error handling for API_SECRET when testing API endpoint credentials
This commit is contained in:
parent
bf2248c33a
commit
3c19ac08cd
@ -27,11 +27,14 @@ class AccountApiController extends BaseAPIController
|
|||||||
$this->accountRepo = $accountRepo;
|
$this->accountRepo = $accountRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ping()
|
public function ping(Request $request)
|
||||||
{
|
{
|
||||||
$headers = Utils::getApiHeaders();
|
$headers = Utils::getApiHeaders();
|
||||||
|
|
||||||
return Response::make(RESULT_SUCCESS, 200, $headers);
|
if(hash_equals(env(API_SECRET),$request->api_secret))
|
||||||
|
return Response::make(RESULT_SUCCESS, 200, $headers);
|
||||||
|
else
|
||||||
|
return $this->errorResponse(['message'=>'API Secret does not match .env variable'], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register(RegisterRequest $request)
|
public function register(RegisterRequest $request)
|
||||||
|
@ -38,7 +38,7 @@ class ApiCheck {
|
|||||||
// check API secret
|
// check API secret
|
||||||
if ( ! $hasApiSecret) {
|
if ( ! $hasApiSecret) {
|
||||||
sleep(ERROR_DELAY);
|
sleep(ERROR_DELAY);
|
||||||
return Response::json('Invalid value for API_SECRET', 403, $headers);
|
return Response::json(['message'=>'Invalid value for API_SECRET'], 403, $headers);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// check for a valid token
|
// check for a valid token
|
||||||
@ -50,7 +50,7 @@ class ApiCheck {
|
|||||||
Session::set('token_id', $token->id);
|
Session::set('token_id', $token->id);
|
||||||
} else {
|
} else {
|
||||||
sleep(ERROR_DELAY);
|
sleep(ERROR_DELAY);
|
||||||
return Response::json('Invalid token', 403, $headers);
|
return Response::json(['message'=>'Invalid token'], 403, $headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ class ApiCheck {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!Utils::hasFeature(FEATURE_API) && !$hasApiSecret) {
|
if (!Utils::hasFeature(FEATURE_API) && !$hasApiSecret) {
|
||||||
return Response::json('API requires pro plan', 403, $headers);
|
return Response::json(['message'=>'API requires pro plan'], 403, $headers);
|
||||||
} else {
|
} else {
|
||||||
$key = Auth::check() ? Auth::user()->account->id : $request->getClientIp();
|
$key = Auth::check() ? Auth::user()->account->id : $request->getClientIp();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user