Skip to content

Commit 401ebab

Browse files
avandenbogaertveewee
authored andcommitted
explode trace on newline, so trace is returned in an array & is more readable (#4)
* make exception trace an array so it is more readable * update readme.md
1 parent 6f77909 commit 401ebab

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,25 @@ new ExceptionApiProblem(new \Exception('message', 500));
6363
"code": 500,
6464
"line": 23,
6565
"file": "exception.php",
66-
"trace": "#0 [internal function]: ...",
66+
"trace": [
67+
"#0 [internal function]: ...",
68+
"#1 [internal function]: ...",
69+
"#3 [internal function]: ...",
70+
"..."
71+
],
6772
"previous": [
6873
{
6974
"message": "previous",
7075
"type": "InvalidArgumentException",
7176
"code": 0,
7277
"line": 20,
7378
"file": "exception.php",
74-
"trace": "#0 [internal function]: ..."
79+
"trace": [
80+
"#0 [internal function]: ...",
81+
"#1 [internal function]: ...",
82+
"#3 [internal function]: ...",
83+
"..."
84+
]
7585
}
7686
]
7787
}

spec/Http/ExceptionApiProblemSpec.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function it_can_parse_to_debuggable_array(): void
7070
'code' => 500,
7171
'line' => $exception->getLine(),
7272
'file' => $exception->getFile(),
73-
'trace' => $exception->getTraceAsString(),
73+
'trace' => explode("\n", $exception->getTraceAsString()),
7474
'previous' => [],
7575
],
7676
]);
@@ -94,23 +94,23 @@ public function it_contains_flattened_previous_exceptions_in_debuggable_output()
9494
'code' => 0,
9595
'line' => $exception->getLine(),
9696
'file' => $exception->getFile(),
97-
'trace' => $exception->getTraceAsString(),
97+
'trace' => explode("\n", $exception->getTraceAsString()),
9898
'previous' => [
9999
[
100100
'type' => Exception::class,
101101
'message' => 'previous',
102102
'code' => 2,
103103
'line' => $previous->getLine(),
104104
'file' => $previous->getFile(),
105-
'trace' => $previous->getTraceAsString(),
105+
'trace' => explode("\n", $previous->getTraceAsString()),
106106
],
107107
[
108108
'type' => Exception::class,
109109
'message' => 'first',
110110
'code' => 1,
111111
'line' => $first->getLine(),
112112
'file' => $first->getFile(),
113-
'trace' => $first->getTraceAsString(),
113+
'trace' => explode("\n", $first->getTraceAsString()),
114114
],
115115
],
116116
],

src/Http/ExceptionApiProblem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private function serializeException(Throwable $throwable): array
5656
'code' => $throwable->getCode(),
5757
'line' => $throwable->getLine(),
5858
'file' => $throwable->getFile(),
59-
'trace' => $throwable->getTraceAsString(),
59+
'trace' => explode("\n", $throwable->getTraceAsString()),
6060
];
6161
}
6262
}

0 commit comments

Comments
 (0)