diff --git a/CHANGELOG.md b/CHANGELOG.md index 53057e0..93ad374 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ v1.7 - Fix FLEXIAPI-252 Update the hCaptcha Laravel library, use file instead of cookies to store the session to prevent empty errors bags - Fix FLEXIAPI-254 Allow no data on POST requests to not trigger the ValidateJSON middleware - Fix FLEXIAPI-255 Create a INSTALL.md tutorial and log FlexisipPusherConnector errors +* Fix FLEXIAPI-257 Return a more coherent message when search API endpoints returns a 404 v1.6 ---- diff --git a/flexiapi/app/Http/Controllers/Api/Admin/AccountController.php b/flexiapi/app/Http/Controllers/Api/Admin/AccountController.php index abefc63..4ab3e19 100644 --- a/flexiapi/app/Http/Controllers/Api/Admin/AccountController.php +++ b/flexiapi/app/Http/Controllers/Api/Admin/AccountController.php @@ -58,12 +58,20 @@ class AccountController extends Controller public function search(string $sip) { - return Account::sip($sip)->firstOrFail(); + $account = Account::sip($sip)->first(); + + if (!$account) abort(404, 'SIP address not found'); + + return $account; } public function searchByEmail(string $email) { - return Account::where('email', $email)->firstOrFail(); + $account = Account::where('email', $email)->first(); + + if (!$account) abort(404, 'Email address not found'); + + return $account; } public function destroy(Request $request, int $accountId) diff --git a/flexiapi/tests/Feature/ApiAccountTest.php b/flexiapi/tests/Feature/ApiAccountTest.php index 7fbe954..e7622ca 100644 --- a/flexiapi/tests/Feature/ApiAccountTest.php +++ b/flexiapi/tests/Feature/ApiAccountTest.php @@ -1231,6 +1231,10 @@ class ApiAccountTest extends TestCase 'activated' => true ]); + $this->keyAuthenticated($admin) + ->get($this->route . '/wrong/search') + ->assertStatus(404); + $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->email . '/search-by-email') ->assertStatus(200) diff --git a/flexiapi/tests/TestUtilsTrait.php b/flexiapi/tests/TestUtilsTrait.php index c6f31e5..89391ea 100644 --- a/flexiapi/tests/TestUtilsTrait.php +++ b/flexiapi/tests/TestUtilsTrait.php @@ -33,6 +33,8 @@ trait TestUtilsTrait { return $this->withHeaders([ 'x-api-key' => $account->apiKey->key, + 'content-type' => 'application/json', + 'accept' => 'application/json', ]); }