Skip to content

Commit 8194508

Browse files
committed
include detail if present
1 parent d8d86f9 commit 8194508

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/client/src/relewise.client.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export interface RelewiseRequestOptions {
1010
}
1111

1212
export class ProblemDetailsError extends Error {
13-
private _details?: HttpProblemDetails;
13+
private _details?: HttpProblemDetails | null;
1414

15-
public get details(): HttpProblemDetails | undefined {
15+
public get details(): HttpProblemDetails | undefined | null {
1616
return this._details;
1717
}
1818

19-
constructor(message: string, details?: HttpProblemDetails) {
19+
constructor(message: string, details?: HttpProblemDetails | null) {
2020
super(message);
2121
this._details = details;
2222
}
@@ -66,13 +66,16 @@ export abstract class RelewiseClient {
6666
});
6767

6868
if (!response.ok) {
69-
let responseMessage = null;
69+
let responseMessage: HttpProblemDetails | null = null;
70+
7071
try {
7172
responseMessage = await response.json();
7273
} catch (_) {
7374
}
7475

75-
throw new ProblemDetailsError(`Error when calling the Relewise API.\n\nTitle: ${response.statusText}\nStatus: ${response.status}\n\nRead more in the details property if there is error response or look in the network tab.`, responseMessage);
76+
const details = responseMessage?.detail ? `Details: ${responseMessage.detail}\n` : '';
77+
78+
throw new ProblemDetailsError(`Error when calling the Relewise API.\n\nTitle: ${response.statusText}\nStatus: ${response.status}\n${details}\nRead more in the details property if there is error response or look in the network tab.`, responseMessage);
7679
}
7780

7881
try {

0 commit comments

Comments
 (0)