. * * @link https://www.librenms.org * @copyright 2020 Tony Murray * @author Tony Murray */ namespace LibreNMS\Exceptions; use Illuminate\Support\Str; use LibreNMS\Interfaces\Exceptions\UpgradeableException; use Symfony\Component\Debug\Exception\FatalErrorException; class MaximumExecutionTimeExceeded extends \Exception implements UpgradeableException { /** * Try to convert the given Exception to a FilePermissionsException * * @param \Exception $exception * @return static */ public static function upgrade($exception) { // cannot write to storage directory if ($exception instanceof FatalErrorException && Str::startsWith($exception->getMessage(), 'Maximum execution time of')) { return new static($exception->getMessage(), $exception->getCode(), $exception); } return null; } /** * Render the exception into an HTTP or JSON response. * * @param \Illuminate\Http\Request * @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response */ public function render(\Illuminate\Http\Request $request) { $title = preg_match('/ (\d+) /', $this->message, $matches) ? trans_choice('exceptions.maximum_execution_time_exceeded.title', $matches[1], ['seconds' => $matches[1]]) : $this->getMessage(); $message = trans('exceptions.maximum_execution_time_exceeded.message'); return $request->wantsJson() ? response()->json([ 'status' => 'error', 'message' => "$title: $message", ]) : response()->view('errors.generic', [ 'title' => $title, 'content' => $message, ]); } }