Skip to content

Commit

Permalink
explode trace on newline, so trace is returned in an array & is more …
Browse files Browse the repository at this point in the history
…readable (#4)

* make exception trace an array so it is more readable
* update readme.md
  • Loading branch information
avandenbogaert authored and veewee committed Jan 30, 2019
1 parent 6f77909 commit 401ebab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,25 @@ new ExceptionApiProblem(new \Exception('message', 500));
"code": 500,
"line": 23,
"file": "exception.php",
"trace": "#0 [internal function]: ...",
"trace": [
"#0 [internal function]: ...",
"#1 [internal function]: ...",
"#3 [internal function]: ...",
"..."
],
"previous": [
{
"message": "previous",
"type": "InvalidArgumentException",
"code": 0,
"line": 20,
"file": "exception.php",
"trace": "#0 [internal function]: ..."
"trace": [
"#0 [internal function]: ...",
"#1 [internal function]: ...",
"#3 [internal function]: ...",
"..."
]
}
]
}
Expand Down
8 changes: 4 additions & 4 deletions spec/Http/ExceptionApiProblemSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function it_can_parse_to_debuggable_array(): void
'code' => 500,
'line' => $exception->getLine(),
'file' => $exception->getFile(),
'trace' => $exception->getTraceAsString(),
'trace' => explode("\n", $exception->getTraceAsString()),
'previous' => [],
],
]);
Expand All @@ -94,23 +94,23 @@ public function it_contains_flattened_previous_exceptions_in_debuggable_output()
'code' => 0,
'line' => $exception->getLine(),
'file' => $exception->getFile(),
'trace' => $exception->getTraceAsString(),
'trace' => explode("\n", $exception->getTraceAsString()),
'previous' => [
[
'type' => Exception::class,
'message' => 'previous',
'code' => 2,
'line' => $previous->getLine(),
'file' => $previous->getFile(),
'trace' => $previous->getTraceAsString(),
'trace' => explode("\n", $previous->getTraceAsString()),
],
[
'type' => Exception::class,
'message' => 'first',
'code' => 1,
'line' => $first->getLine(),
'file' => $first->getFile(),
'trace' => $first->getTraceAsString(),
'trace' => explode("\n", $first->getTraceAsString()),
],
],
],
Expand Down
2 changes: 1 addition & 1 deletion src/Http/ExceptionApiProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private function serializeException(Throwable $throwable): array
'code' => $throwable->getCode(),
'line' => $throwable->getLine(),
'file' => $throwable->getFile(),
'trace' => $throwable->getTraceAsString(),
'trace' => explode("\n", $throwable->getTraceAsString()),
];
}
}

0 comments on commit 401ebab

Please sign in to comment.