Skip to content

Commit

Permalink
fix: prevent render error in production (#389)
Browse files Browse the repository at this point in the history
* fix: convert env (string) to integer

* prevent render error in production
  • Loading branch information
SonyPradana authored Sep 20, 2024
1 parent 83bf27a commit e647152
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/System/Integrate/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function loadConfig(ConfigRepository $configs): void

// base env
$this->set('environment', $configs['APP_ENV'] ?? $configs['ENVIRONMENT']);
$this->set('app.debug', $configs['APP_DEBUG']);
$this->set('app.debug', $configs['APP_DEBUG'] === 'true');
// application path
$this->setAppPath($this->basePath());
$this->setModelPath($configs['MODEL_PATH']);
Expand Down Expand Up @@ -294,7 +294,7 @@ public function defaultConfigs()
'time_zone' => 'Asia/Jakarta',
'APP_KEY' => '',
'ENVIRONMENT' => 'dev',
'APP_DEBUG' => false,
'APP_DEBUG' => 'false',

'COMMAND_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Commands' . DIRECTORY_SEPARATOR,
'CONTROLLER_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR,
Expand Down
11 changes: 9 additions & 2 deletions src/System/Integrate/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ protected function handleJsonResponse(\Throwable $th): Response

protected function handleResponse(\Throwable $th): Response
{
return new Response($th->getMessage(), 500);
return $this->isProduction()
? $this->handleHttpException(new HttpException(500, 'Internal Server Error'))
: new Response($th->getMessage(), 500);
}

protected function handleHttpException(HttpException $e): Response
Expand Down Expand Up @@ -157,6 +159,11 @@ public function registerViewPath(): Templator

private function isDebug(): bool
{
return $this->app->get('app.debug') ?? false;
return $this->app->get('app.debug');
}

private function isProduction(): bool
{
return $this->app->get('environment') === 'prod';
}
}
2 changes: 1 addition & 1 deletion tests/Integrate/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private function defaultConfigs()
'time_zone' => 'Asia/Jakarta',
'APP_KEY' => '',
'ENVIRONMENT' => 'dev',
'APP_DEBUG' => false,
'APP_DEBUG' => 'false',

'COMMAND_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Commands' . DIRECTORY_SEPARATOR,
'CONTROLLER_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR,
Expand Down

0 comments on commit e647152

Please sign in to comment.