Fix FLEXIAPI-257 Return a more coherent message when search API endpoints returns a 404

This commit is contained in:
Timothée Jaussoin 2025-01-07 14:48:22 +01:00
parent 786258da1f
commit 07458db5c9
4 changed files with 17 additions and 2 deletions

View file

@ -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
----

View file

@ -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)

View file

@ -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)

View file

@ -33,6 +33,8 @@ trait TestUtilsTrait
{
return $this->withHeaders([
'x-api-key' => $account->apiKey->key,
'content-type' => 'application/json',
'accept' => 'application/json',
]);
}