diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-08-21 10:50:44 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-08-21 10:50:44 +0200 |
commit | 0c6fdbe12bbbb336348666b14b82096f24d5858b (patch) | |
tree | 8fad2829c55f94022e359fa8914e11f80a2afc2a /application/front/ShaarliMiddleware.php | |
parent | bedbb845eec20363b928b424143787dbe988eefe (diff) | |
download | Shaarli-0c6fdbe12bbbb336348666b14b82096f24d5858b.tar.gz Shaarli-0c6fdbe12bbbb336348666b14b82096f24d5858b.tar.zst Shaarli-0c6fdbe12bbbb336348666b14b82096f24d5858b.zip |
Move error handling to dedicated controller instead of middleware
Diffstat (limited to 'application/front/ShaarliMiddleware.php')
-rw-r--r-- | application/front/ShaarliMiddleware.php | 26 |
1 files changed, 1 insertions, 25 deletions
diff --git a/application/front/ShaarliMiddleware.php b/application/front/ShaarliMiddleware.php index a2a3837b..c015c0c6 100644 --- a/application/front/ShaarliMiddleware.php +++ b/application/front/ShaarliMiddleware.php | |||
@@ -3,7 +3,6 @@ | |||
3 | namespace Shaarli\Front; | 3 | namespace Shaarli\Front; |
4 | 4 | ||
5 | use Shaarli\Container\ShaarliContainer; | 5 | use Shaarli\Container\ShaarliContainer; |
6 | use Shaarli\Front\Exception\ShaarliFrontException; | ||
7 | use Shaarli\Front\Exception\UnauthorizedException; | 6 | use Shaarli\Front\Exception\UnauthorizedException; |
8 | use Slim\Http\Request; | 7 | use Slim\Http\Request; |
9 | use Slim\Http\Response; | 8 | use Slim\Http\Response; |
@@ -53,35 +52,12 @@ class ShaarliMiddleware | |||
53 | $this->checkOpenShaarli($request, $response, $next); | 52 | $this->checkOpenShaarli($request, $response, $next); |
54 | 53 | ||
55 | return $next($request, $response); | 54 | return $next($request, $response); |
56 | } catch (ShaarliFrontException $e) { | ||
57 | // Possible functional error | ||
58 | $this->container->pageBuilder->reset(); | ||
59 | $this->container->pageBuilder->assign('message', nl2br($e->getMessage())); | ||
60 | |||
61 | $response = $response->withStatus($e->getCode()); | ||
62 | |||
63 | return $response->write($this->container->pageBuilder->render('error', $this->container->basePath)); | ||
64 | } catch (UnauthorizedException $e) { | 55 | } catch (UnauthorizedException $e) { |
65 | $returnUrl = urlencode($this->container->environment['REQUEST_URI']); | 56 | $returnUrl = urlencode($this->container->environment['REQUEST_URI']); |
66 | 57 | ||
67 | return $response->withRedirect($this->container->basePath . '/login?returnurl=' . $returnUrl); | 58 | return $response->withRedirect($this->container->basePath . '/login?returnurl=' . $returnUrl); |
68 | } catch (\Throwable $e) { | ||
69 | // Unknown error encountered | ||
70 | $this->container->pageBuilder->reset(); | ||
71 | if ($this->container->conf->get('dev.debug', false)) { | ||
72 | $this->container->pageBuilder->assign('message', $e->getMessage()); | ||
73 | $this->container->pageBuilder->assign( | ||
74 | 'stacktrace', | ||
75 | nl2br(get_class($e) .': '. PHP_EOL . $e->getTraceAsString()) | ||
76 | ); | ||
77 | } else { | ||
78 | $this->container->pageBuilder->assign('message', t('An unexpected error occurred.')); | ||
79 | } | ||
80 | |||
81 | $response = $response->withStatus(500); | ||
82 | |||
83 | return $response->write($this->container->pageBuilder->render('error', $this->container->basePath)); | ||
84 | } | 59 | } |
60 | // Other exceptions are handled by ErrorController | ||
85 | } | 61 | } |
86 | 62 | ||
87 | /** | 63 | /** |