Skip to content

Commit 362a92b

Browse files
author
David Wilcock
authored
Merge pull request #10 from tomwalder/feat/better-exception-handling
Hide exception messages from responses. Merged on this occasion, but please ensure that your commits don't adversely affect code coverage in future!
2 parents 46fa6de + 3974502 commit 362a92b

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/Docnet/JAPI.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ class JAPI implements LoggerAwareInterface
3535

3636
use HasLogger;
3737

38+
/**
39+
* Should we expose detailed error information in responses?
40+
*
41+
* @var bool
42+
*/
43+
private $bol_expose_errors = false;
44+
3845
/**
3946
* Hook up the shutdown function so we always send nice JSON error responses
4047
*/
@@ -93,8 +100,6 @@ public function timeToDie()
93100
/**
94101
* Whatever went wrong, let 'em have it in JSON over HTTP
95102
*
96-
* @todo Environment or LIVE check for extended error
97-
*
98103
* @param \Exception $obj_error
99104
* @param int $int_code
100105
*/
@@ -105,7 +110,7 @@ protected function jsonError(\Exception $obj_error, $int_code)
105110
'msg' => ($obj_error instanceof \ErrorException ? 'Internal Error' : 'Exception')
106111
];
107112
$str_log_message = get_class($obj_error) . ': ' . $obj_error->getMessage();
108-
if(TRUE) { // @todo Environment or LIVE check
113+
if($this->bol_expose_errors) {
109114
$arr_response['detail'] = $str_log_message;
110115
}
111116
if($int_code < 400 || $int_code > 505) {
@@ -129,4 +134,14 @@ protected function sendResponse($response, $http_code = 200)
129134
echo json_encode($response);
130135
}
131136

137+
/**
138+
* Tell JAPI to expose error detail, or not!
139+
*
140+
* @param bool $bol_expose
141+
*/
142+
public function exposeErrorDetail($bol_expose = true)
143+
{
144+
$this->bol_expose_errors = $bol_expose;
145+
}
146+
132147
}

0 commit comments

Comments
 (0)