/** * Register core exception handler and http status code hanlding. * Exception instance can be accessed in errorHandler service. * * @return \Avenue\App */ protected function registerExceptionHandler() { set_exception_handler(function (\Exception $exception) { $this->exception = $exception; $code = $this->exception->getCode(); $statusCode = $this->response->getStatusCode(); if (!is_int($code) || $code < 400 || $code > 599) { $code = 500; } // overwrite with user defined if ((int) $statusCode >= 400) { $code = $statusCode; } $this->response->withStatus($code); $this->resolve('errorHandler'); }); return $this; }
public function testBothCustomExceptionAndCoreExceptionCodeAreTheSame() { $base = new \Exception('yo! I am exception.', 100); $exception = new Exception($this->app, $base); $this->assertEquals($exception->getCode(), $base->getCode()); }