Skip to content

Commit c15b524

Browse files
committed
fix: enhance error handling in login method and improve exception management
1 parent c26a729 commit c15b524

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

app/Controllers/Api/AuthController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Core\Routing\Controller;
99
use Core\Http\Respond;
1010
use Core\Support\Time;
11+
use Exception;
1112
use Firebase\JWT\JWT;
13+
use Throwable;
1214

1315
class AuthController extends Controller
1416
{
@@ -20,7 +22,11 @@ public function login(AuthRequest $request, JsonResponse $json): JsonResponse
2022
return $json->errorBadRequest($valid->messages());
2123
}
2224

23-
if (!Auth::attempt($valid->only(['email', 'password']))) {
25+
try {
26+
if (!Auth::attempt($valid->only(['email', 'password']))) {
27+
throw new Exception('Invalid credentials');
28+
}
29+
} catch (Throwable) {
2430
return $json->error(Respond::HTTP_UNAUTHORIZED);
2531
}
2632

docker/php/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/*
99
RUN docker-php-ext-install pdo zip pdo_pgsql pgsql opcache
1010
RUN docker-php-ext-enable pdo zip pdo_pgsql pgsql opcache
1111

12+
COPY /api/php.ini /usr/local/etc/php/conf.d/opcache.ini
13+
1214
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
1315

1416
COPY . /var/www

0 commit comments

Comments
 (0)