Browse Source

attempt to catch fatal errors and print a nice message

pull/39/head
Aaron Parecki 8 years ago
parent
commit
1a1215c0be
No known key found for this signature in database GPG Key ID: 276C2817346D6056
2 changed files with 20 additions and 1 deletions
  1. +1
    -1
      lib/HTTPCurl.php
  2. +19
    -0
      public/index.php

+ 1
- 1
lib/HTTPCurl.php View File

@ -73,7 +73,7 @@ class HTTPCurl {
} }
curl_setopt($ch, CURLOPT_TIMEOUT_MS, round($this->timeout * 1000)); curl_setopt($ch, CURLOPT_TIMEOUT_MS, round($this->timeout * 1000));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 2000);
} }
public static function error_string_from_code($code) { public static function error_string_from_code($code) {

+ 19
- 0
public/index.php View File

@ -2,6 +2,8 @@
chdir('..'); chdir('..');
include('vendor/autoload.php'); include('vendor/autoload.php');
register_shutdown_function('shutdown');
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
$router = new League\Route\RouteCollection; $router = new League\Route\RouteCollection;
@ -29,3 +31,20 @@ try {
$response->setContent("Method not allowed\n"); $response->setContent("Method not allowed\n");
$response->send(); $response->send();
} }
function shutdown() {
$error = error_get_last();
if($error['type'] !== 0) {
header('HTTP/1.1 500 Server Error');
header('X-PHP-Error-Type: '.$error['type']);
header('X-PHP-Error-Message: '.$error['message']);
header('Content-Type: application/json');
echo json_encode([
'error' => 'internal_error',
'error_code' => 500,
'error_description' => $error['message'],
'debug' => 'Please file an issue with any information you have about what caused this error: https://github.com/aaronpk/XRay/issues'
]);
die();
}
}

Loading…
Cancel
Save