/** * 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 testGetAppIDInException() { $appId = 'testexceptionappid'; $app = new App(['timezone' => 'UTC'], $appId); $exception = new Exception($this->app, new \RuntimeException('yo! I am runtime exception.')); $this->assertEquals($appId, $exception->getAppId()); }
/** * Get formatted string of trace. * * @return string */ public function getTraceAsString() { return $this->exception->getTraceAsString(); }