handle($request); } catch (ValidationException $th) { return new JsonResponse( [ 'code' => $th->getCode(), 'message' => $th->getMessage(), 'param' => $th->getParam() ], StatusCode::BAD_REQUEST ); } catch (UnauthorizedException $th) { $path = $request->getUri()->getPath(); if ( str_starts_with($path, '/admin/api') !== false || str_starts_with($path, '/api') !== false ) { return new JsonResponse( [ 'message' => $th->getMessage(), 'param' => $th->param ], $th->statusCode ); } $uri = $this->uriFactory->createUri('/login'); // Set redirect query string $path = $request->getUri()->getPath(); if ($path && $path !== '/') { $uri = $uri->withQuery('redirect=' . $path); } $resp = new RedirectResponse($uri); $cookie = UserCookie::createFromRequest($request); if ($cookie) { $resp = $resp->withAddedHeader( 'Set-Cookie', $cookie->toHeaderValue(true) ); } return $resp; } catch (HttpException $th) { return new JsonResponse( [ 'message' => $th->getMessage(), 'param' => $th->param ], $th->statusCode ); } catch (InvalidValueException $th) { return new JsonResponse( [ 'message' => $th->getMessage() ], StatusCode::BAD_REQUEST ); } catch (\Throwable $th) { if (!$this->enableDebugging) { return new EmptyResponse(StatusCode::INTERNAL_SERVER_ERROR); } throw $th; } } }