<?php

namespace App\Exceptions;

use Exception;
use Throwable;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;

class Handler extends ExceptionHandler
{

	/**
	 * A list of the exception types that should not be reported.
	 *
	 * @var array
	 */
	protected $dontReport = [
		'Symfony\Component\HttpKernel\Exception\HttpException'
	];

	/**
	 * Report or log an exception.
	 *
	 * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
	 *
	 * @param  \Throwable  $e
	 * @return void
	 */
	public function report(Throwable $e)
	{
		// Laravel 5.0 parent expects an Exception; wrap Error instances so
		// PHP 7+ fatal errors (TypeError, ParseError, etc.) are handled safely.
		if (!$e instanceof Exception) {
			$e = new \RuntimeException($e->getMessage(), $e->getCode());
		}
		return parent::report($e);
	}

	/**
	 * Render an exception into an HTTP response.
	 *
	 * @param  \Illuminate\Http\Request  $request
	 * @param  \Exception  $e
	 * @return \Illuminate\Http\Response
	 */
	// public function render($request, Exception $e)
	// {
	// 	return parent::render($request, $e);
	// }

	public function render($request, Throwable $e)
	{
		if ($e instanceof MethodNotAllowedHttpException) {
			abort(404);
		}
		// Wrap non-Exception Throwables for Laravel 5.0 parent compatibility.
		$exception = $e instanceof Exception ? $e : new \RuntimeException($e->getMessage(), $e->getCode());
		return parent::render($request, $exception);
	}
}
