55use App \Service \DotCMSService ;
66use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
77use Symfony \Component \HttpFoundation \Response ;
8+ use Symfony \Component \HttpKernel \Exception \BadRequestHttpException ;
89use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
9- use Dotcms \PhpSdk \Exception \DotCMSException ;
10- use Dotcms \PhpSdk \Exception \HttpException ;
11- use Dotcms \PhpSdk \Exception \ResponseException ;
1210use Symfony \Component \HttpKernel \Exception \ServiceUnavailableHttpException ;
13- use Symfony \Component \HttpKernel \Exception \BadRequestHttpException ;
1411use Symfony \Component \HttpKernel \Exception \UnauthorizedHttpException ;
12+ use Symfony \Component \HttpKernel \Exception \HttpException as SymfonyHttpException ;
13+ use Dotcms \PhpSdk \Exception \HttpException ;
14+ use Dotcms \PhpSdk \Exception \ResponseException ;
1515
1616class CatchAllController extends AbstractController
1717{
@@ -41,23 +41,18 @@ public function show(string $path = ''): Response
4141 ]);
4242 } catch (HttpException $ e ) {
4343 // Map HTTP errors to appropriate Symfony exceptions
44- $ statusCode = $ e ->getCode ();
45- throw match ( $ statusCode ) {
44+ throw match ( $ e ->getCode ()) {
45+ 400 => new BadRequestHttpException ( $ e -> getMessage (), $ e ),
4646 401 => new UnauthorizedHttpException ('Bearer ' , $ e ->getMessage (), $ e ),
4747 404 => new NotFoundHttpException ($ e ->getMessage (), $ e ),
48- 400 => new BadRequestHttpException ( $ e ->getMessage (), $ e ),
48+ 500 => new SymfonyHttpException ( 500 , $ e ->getMessage (), $ e ),
4949 503 => new ServiceUnavailableHttpException (null , $ e ->getMessage (), $ e ),
50- default => new NotFoundHttpException ( $ e ->getMessage (), $ e )
50+ default => new ServiceUnavailableHttpException ( null , $ e ->getMessage (), $ e )
5151 };
5252 } catch (ResponseException $ e ) {
53- // Handle response parsing errors
54- throw new BadRequestHttpException ('Invalid response from DotCMS: ' . $ e ->getMessage (), $ e );
55- } catch (DotCMSException $ e ) {
56- // Handle any other DotCMS specific errors
57- throw new ServiceUnavailableHttpException (null , 'DotCMS Error: ' . $ e ->getMessage (), $ e );
58- } catch (\Exception $ e ) {
59- // Handle any other unexpected errors
60- throw new ServiceUnavailableHttpException (null , 'Unexpected error: ' . $ e ->getMessage (), $ e );
53+ // ResponseException indicates invalid/missing data in the response
54+ // This is a server error since the response format is controlled by DotCMS
55+ throw new ServiceUnavailableHttpException (null , $ e ->getMessage (), $ e );
6156 }
6257 }
6358}
0 commit comments