Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/aphront/handler/PhabricatorDefaultRequestExceptionHandler.php
12241 views
1
<?php
2
3
final class PhabricatorDefaultRequestExceptionHandler
4
extends PhabricatorRequestExceptionHandler {
5
6
public function getRequestExceptionHandlerPriority() {
7
return 900000;
8
}
9
10
public function getRequestExceptionHandlerDescription() {
11
return pht('Handles all other exceptions.');
12
}
13
14
public function canHandleRequestThrowable(
15
AphrontRequest $request,
16
$throwable) {
17
18
if (!$this->isPhabricatorSite($request)) {
19
return false;
20
}
21
22
return true;
23
}
24
25
public function handleRequestThrowable(
26
AphrontRequest $request,
27
$throwable) {
28
29
$viewer = $this->getViewer($request);
30
31
// Some types of uninteresting request exceptions don't get logged, usually
32
// because they are caused by the background radiation of bot traffic on
33
// the internet. These include requests with bad CSRF tokens and
34
// questionable "Host" headers.
35
$should_log = true;
36
if ($throwable instanceof AphrontMalformedRequestException) {
37
$should_log = !$throwable->getIsUnlogged();
38
}
39
40
if ($should_log) {
41
phlog($throwable);
42
}
43
44
$class = get_class($throwable);
45
$message = $throwable->getMessage();
46
47
if ($throwable instanceof AphrontSchemaQueryException) {
48
$message .= "\n\n".pht(
49
"NOTE: This usually indicates that the MySQL schema has not been ".
50
"properly upgraded. Run '%s' to ensure your schema is up to date.",
51
'bin/storage upgrade');
52
}
53
54
if (PhabricatorEnv::getEnvConfig('phabricator.developer-mode')) {
55
$trace = id(new AphrontStackTraceView())
56
->setUser($viewer)
57
->setTrace($throwable->getTrace());
58
} else {
59
$trace = null;
60
}
61
62
$content = phutil_tag(
63
'div',
64
array('class' => 'aphront-unhandled-exception'),
65
array(
66
phutil_tag('div', array('class' => 'exception-message'), $message),
67
$trace,
68
));
69
70
$dialog = new AphrontDialogView();
71
$dialog
72
->setTitle(pht('Unhandled Exception ("%s")', $class))
73
->setClass('aphront-exception-dialog')
74
->setUser($viewer)
75
->appendChild($content);
76
77
if ($request->isAjax()) {
78
$dialog->addCancelButton('/', pht('Close'));
79
}
80
81
return id(new AphrontDialogResponse())
82
->setDialog($dialog)
83
->setHTTPResponseCode(500);
84
}
85
86
}
87
88