Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nextcloud mail - PostGuard
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Laura Kolijn
Nextcloud mail - PostGuard
Commits
f14311e2
Unverified
Commit
f14311e2
authored
5 years ago
by
Christoph Wurst
Browse files
Options
Downloads
Patches
Plain Diff
Return full exception trace
Signed-off-by:
Christoph Wurst
<
christoph@winzerhof-wurst.at
>
parent
c65803fa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/Http/Middleware/ErrorMiddleware.php
+23
-9
23 additions, 9 deletions
lib/Http/Middleware/ErrorMiddleware.php
tests/Unit/Http/Middleware/ErrorMiddlewareTest.php
+17
-0
17 additions, 0 deletions
tests/Unit/Http/Middleware/ErrorMiddlewareTest.php
with
40 additions
and
9 deletions
lib/Http/Middleware/ErrorMiddleware.php
+
23
−
9
View file @
f14311e2
...
...
@@ -39,6 +39,7 @@ use OCP\AppFramework\Middleware;
use
OCP\AppFramework\Utility\IControllerMethodReflector
;
use
OCP\IConfig
;
use
OCP\ILogger
;
use
function
get_class
;
class
ErrorMiddleware
extends
Middleware
{
...
...
@@ -67,6 +68,7 @@ class ErrorMiddleware extends Middleware {
* @param Controller $controller
* @param string $methodName
* @param Exception $exception
*
* @return Response
* @throws Exception
*/
...
...
@@ -86,17 +88,29 @@ class ErrorMiddleware extends Middleware {
}
else
{
$this
->
logger
->
logException
(
$exception
);
if
(
$this
->
config
->
getSystemValue
(
'debug'
,
false
))
{
return
new
JSONErrorResponse
([
'debug'
=>
true
,
'type'
=>
get_class
(
$exception
),
'message'
=>
$exception
->
getMessage
(),
'code'
=>
$exception
->
getCode
(),
'trace'
=>
$this
->
filterTrace
(
$exception
->
getTrace
()),
],
Http
::
STATUS_INTERNAL_SERVER_ERROR
);
}
else
{
return
new
JSONErrorResponse
([],
Http
::
STATUS_INTERNAL_SERVER_ERROR
);
return
new
JSONErrorResponse
(
array_merge
(
[
'debug'
=>
true
,
],
$this
->
serializeException
(
$exception
)
),
Http
::
STATUS_INTERNAL_SERVER_ERROR
);
}
return
new
JSONErrorResponse
([],
Http
::
STATUS_INTERNAL_SERVER_ERROR
);
}
}
private
function
serializeException
(
?Exception
$exception
):
?array
{
if
(
$exception
===
null
)
{
return
null
;
}
return
[
'type'
=>
get_class
(
$exception
),
'message'
=>
$exception
->
getMessage
(),
'code'
=>
$exception
->
getCode
(),
'trace'
=>
$this
->
filterTrace
(
$exception
->
getTrace
()),
'previous'
=>
$this
->
serializeException
(
$exception
->
getPrevious
()),
];
}
private
function
filterTrace
(
array
$original
):
array
{
...
...
This diff is collapsed.
Click to expand it.
tests/Unit/Http/Middleware/ErrorMiddlewareTest.php
+
17
−
0
View file @
f14311e2
...
...
@@ -25,6 +25,7 @@
namespace
OCA\Mail\Tests\Unit\Http\Middleware
;
use
ChristophWurst\Nextcloud\Testing\TestCase
;
use
Exception
;
use
OCA\Mail\Exception\NotImplemented
;
use
OCA\Mail\Exception\ServiceException
;
use
OCA\Mail\Http\Middleware\ErrorMiddleware
;
...
...
@@ -108,4 +109,20 @@ class ErrorMiddlewareTest extends TestCase {
$this
->
assertEquals
(
$expectedStatus
,
$response
->
getStatus
());
}
public
function
testSerializesRecursively
()
{
$inner
=
new
Exception
();
$outer
=
new
ServiceException
(
"Test"
,
0
,
$inner
);
$controller
=
$this
->
createMock
(
Controller
::
class
);
$this
->
reflector
->
expects
(
$this
->
once
())
->
method
(
'hasAnnotation'
)
->
willReturn
(
true
);
$this
->
logger
->
expects
(
$this
->
once
())
->
method
(
'logException'
)
->
with
(
$outer
);
$response
=
$this
->
middleware
->
afterException
(
$controller
,
'index'
,
$outer
);
$this
->
assertInstanceOf
(
JSONResponse
::
class
,
$response
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment