Skip to content

Commit

Permalink
Merge pull request #77 from bowphp/5.x-ref-update
Browse files Browse the repository at this point in the history
[5.x] Structure formating
  • Loading branch information
papac authored May 27, 2023
2 parents a1399f3 + 3a11aa5 commit 8216f8e
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 58 deletions.
2 changes: 1 addition & 1 deletion app/Configurations/ApplicationConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ApplicationConfiguration extends Configuration
*/
public function create(Loader $config): void
{
// Event::on("user.created", UserCreatedListener::class);
//
}

/**
Expand Down
55 changes: 0 additions & 55 deletions app/Exceptions/ErrorHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
namespace App\Exceptions;

use Exception;
use PDOException;
use Bow\Http\Exception\HttpException;
use Policier\Exception\TokenExpiredException;
use Policier\Exception\TokenInvalidException;
use Bow\Application\Exception\BaseErrorHandler;
use Bow\Http\Exception\ResponseException as HttpResponseException;
use Bow\Database\Exception\NotFoundException as ModelNotFoundException;
Expand Down Expand Up @@ -42,56 +39,4 @@ public function handle($exception): mixed
]);
}
}

/**
* Send the json as response
*
* @param string $data
* @param mixed $code
* @return mixed
*/
private function json($exception, $code = null)
{
if ($exception instanceof TokenInvalidException) {
$code = 'TOKEN_INVALID';
}

if ($exception instanceof TokenExpiredException) {
$code = 'TOKEN_EXPIRED';
}

if (is_null($code)) {
if (method_exists($exception, 'getStatus')) {
$code = $exception->getStatus();
} else {
$code = 'INTERNAL_SERVER_ERROR';
}
}

if (app_env("APP_ENV") == "production" && $exception instanceof PDOException) {
$message = 'Internal error occured';
} else {
$message = $exception->getMessage();
}

$error = [
'message' => $message,
'code' => $code,
'time' => date('Y-m-d H:i:s')
];

if (config('app.error_trace')) {
$trace = $exception->getTrace();
} else {
$trace = [];
}

if ($exception instanceof HttpException) {
$status = $exception->getStatusCode();
} else {
$status = 500;
}

return json(compact('error', 'trace'), $status);
}
}
2 changes: 1 addition & 1 deletion app/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function namespaces(): array
}

/**
* Define the app middlewares
* Define the app middleware
*
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion config/translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
/**
* Path to the language repeater
*/
'dictionary' => __DIR__ . '/../frontend/lang',
'dictionary' => __DIR__ . '/../lang',
];
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8216f8e

Please sign in to comment.