Skip to content

Commit

Permalink
added ExtendedException, minor update to composer
Browse files Browse the repository at this point in the history
  • Loading branch information
killua-eu committed Aug 6, 2024
1 parent 0a2ecc3 commit 9a8205f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
30 changes: 16 additions & 14 deletions src/ComposerHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Dotenv\Dotenv;
use Glued\Lib\Crypto;
use Grasmash\YamlExpander\YamlExpander;
use mysql_xdevapi\Exception;
use PharData;
use Psr\Log\NullLogger;
use ParagonIE\CSPBuilder\CSPBuilder;
Expand Down Expand Up @@ -138,8 +137,8 @@ public static function generatePHPFPM(): void {
}


public static function generateNginx(): void
{
public static function generateNginx(): void
{
$settings = self::getSettings();
$comment = <<<EOT
# NOTE that when this file is found under /etc/nginx
Expand Down Expand Up @@ -185,16 +184,16 @@ public static function generateNginx(): void


$origins = $settings['nginx']['cors']['origin'];
if (!is_array($settings['nginx']['cors']['origin'])) {
if (!is_array($settings['nginx']['cors']['origin'])) {
$origins = [];
$origins[0] = $settings['nginx']['cors']['origin'];
$origins[0] = $settings['nginx']['cors']['origin'];
}

$output = "map_hash_bucket_size 512;".PHP_EOL;
$output .= 'map $http_origin $origin_allowed {'.PHP_EOL;
$output .= " default 0; # Origin not allowed fallback".PHP_EOL;
foreach ($origins as $o) {
$output .= " ".$o." 1; # Allowed origin".PHP_EOL;
$output .= " ".$o." 1; # Allowed origin".PHP_EOL;
}
$output .= " '' 2; # Special case for missing Origin header".PHP_EOL;
$output .= "}".PHP_EOL.PHP_EOL;
Expand Down Expand Up @@ -247,18 +246,21 @@ public static function configTool(Event $event): void
echo "[INFO] Ensuring paths exist and are writable" . PHP_EOL;
$oldumask = umask(0);
foreach ($paths as $path) {
if (!is_dir($path)) {
echo "[WARN] '.$path.' not found. Attempting to create ... ";
if (!mkdir($path, 0777, true)) {
die('failed.'. PHP_EOL .'[FAIL] Failed to create directories.' . PHP_EOL . PHP_EOL);
}
echo "ok." . PHP_EOL;
}
if (!is_dir($path)) {
echo "[WARN] '.$path.' not found. Attempting to create ... ";
if (!mkdir($path, 0777, true)) {
die('failed.'. PHP_EOL .'[FAIL] Failed to create directories.' . PHP_EOL . PHP_EOL);
}
echo "ok." . PHP_EOL;
}
}

$openApiFile = $_ENV['DATAPATH'] . "/" . basename(__ROOT__) . "/cache/openapi.yaml";
$routesFile = $_ENV['DATAPATH'] . "/" . basename(__ROOT__) . "/cache/routes.yaml";
echo "[INFO] (re)building service routes cache from {$openApiFile} . PHP_EOL";
echo "[INFO] (re)building service routes cache from OpenAPI" . PHP_EOL;
print ">>>>>> OpenAPI source: ".$openApiFile. "\n";
print ">>>>>> Routes target: ".$routesFile. "\n";

try {
self::openApiToRoutes($openApiFile, $routesFile);
} catch (\Exception $e) {
Expand Down
4 changes: 0 additions & 4 deletions src/Exceptions/DbException.php

This file was deleted.

20 changes: 20 additions & 0 deletions src/Exceptions/ExtendedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Glued\Lib\Exceptions;

class ExtendedException extends \Exception
{
protected $details;
public function __construct($message = "", $code = 0, array $details = [])
{
parent::__construct($message, $code);
$this->details = $details;
}

public function getDetails()
{
return $this->details;
}
}


11 changes: 6 additions & 5 deletions src/Includes/json_error_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$r['file'] = $exception->getFile() . ' ' . $exception->getLine();
$short = explode('\\', $r['title']);
$short = (string) array_pop($short);
$r['hint'] = "No hints, sorry.";
$r['details'] = "No details, sorry.";
$http = '500 Internal Server Error';

if ($r['code'] == 400) { $http = '400 Bad Request'; }
Expand All @@ -18,12 +18,13 @@
if ($r['code'] == 404) { $http = '404 Not found'; }
if ($r['code'] == 410) { $http = '410 Gone'; }

if ($short == "AuthJwtException") { $http = '401 Unauthorized'; $r['hint'] = "Login at ".$settings['oidc']['uri']['login']; }
if ($short == "AuthTokenException") { $http = '401 Unauthorized'; $r['hint'] = "Login at ".$settings['oidc']['uri']['login']; }
if ($short == "HttpNotFoundException") { $http = '404 Not Found'; $r['hint'] = "Try: " . $container->get('settings')['glued']['protocol'].$container->get('settings')['glued']['hostname'].$container->get('routecollector')->getRouteParser()->UrlFor('be_core_routes'); }
if ($short == "ExtendedException") { $r['details'] = $exception->getDetails(); }
if ($short == "AuthJwtException") { $http = '401 Unauthorized'; $r['datails'] = "Login at ".$settings['oidc']['uri']['login']; }
if ($short == "AuthTokenException") { $http = '401 Unauthorized'; $r['datails'] = "Login at ".$settings['oidc']['uri']['login']; }
if ($short == "HttpNotFoundException") { $http = '404 Not Found'; $r['datails'] = "Try: " . $container->get('settings')['glued']['protocol'].$container->get('settings')['glued']['hostname'].$container->get('routecollector')->getRouteParser()->UrlFor('be_core_routes'); }
if ($r['title'] == "mysqli_sql_exception") {
$container->get('logger')->error("EXCEPTION HANDLER", [ "SQL query" => $container->get('db')->getLastQuery(), "Exception" => $r ]);
$r['hint'] = "Query logged.";
$r['datails'] = "Query logged.";
}


Expand Down

0 comments on commit 9a8205f

Please sign in to comment.