update handler

This commit is contained in:
khanh97dev 2023-11-09 22:37:44 +07:00
parent 9d95843af6
commit 37d7a4d630
5 changed files with 2013 additions and 21 deletions

View File

@ -1,5 +1,13 @@
FROM docker.io/bitnami/laravel:10
RUN apt update
RUN apt install -y entr
# php.ini
COPY php.ini /opt/bitnami/php/lib/php.ini
# Run
EXPOSE 8000
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT /docker-entrypoint.sh

View File

@ -14,9 +14,8 @@ class UserController extends Controller
{
$this->middleware('auth');
}
public function users()
{
return User::all();
return response()->json(User::all());
}
}

View File

@ -2,10 +2,10 @@
namespace App\Exceptions;
use Exception;
use Dotenv\Exception\ValidationException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Illuminate\Http\Exceptions\HttpResponseException;
use Throwable;
class Handler extends ExceptionHandler
@ -42,21 +42,11 @@ class Handler extends ExceptionHandler
*/
public function render($request, Throwable $exception)
{
if ($request->expectsJson()) {
}
return $this->prepareJsonResponse($request, $exception);
return parent::render($request, $exception);
}
protected function prepareJsonResponse($request, Throwable $exception)
{
return new JsonResponse(
[
'message' => $exception->getMessage(),
'code' => $exception->getCode(),
],
$this->isHttpException($exception) ? $exception->getStatusCode() : Response::HTTP_INTERNAL_SERVER_ERROR
);
return match (true) {
$exception instanceof HttpResponseException => $exception->getResponse(),
$exception instanceof AuthenticationException => $this->unauthenticated($request, $exception),
$exception instanceof ValidationException => $this->convertValidationExceptionToResponse($exception, $request),
default => $this->prepareJsonResponse($request, $exception),
};
}
}

View File

@ -8,4 +8,10 @@ else
composer u
fi
if [ ! -f "$PWD/.env" ]; then
cp .env.example .env
fi
# find . -name '*.php' | entr watch file
php artisan serve --host "0.0.0.0"

1989
php.ini Normal file

File diff suppressed because it is too large Load Diff