Skip to content

Commit

Permalink
Improve RestError output in Node (#7454)
Browse files Browse the repository at this point in the history
Log message and type correctly
  • Loading branch information
xirzec authored Feb 24, 2020
1 parent 0e8ce69 commit 2e45647
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sdk/core/core-http/lib/restError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class RestError extends Error {
response?: HttpOperationResponse
) {
super(message);
this.name = "RestError";
this.code = code;
this.statusCode = statusCode;
this.request = request;
Expand All @@ -37,6 +38,6 @@ export class RestError extends Error {
* Logging method for util.inspect in Node
*/
[custom](): string {
return errorSanitizer.sanitize(this);
return `RestError: ${this.message} \n ${errorSanitizer.sanitize(this)}`;
}
}
8 changes: 8 additions & 0 deletions sdk/core/core-http/lib/util/sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ export class Sanitizer {
}

private replacer(key: string, value: unknown) {
// Ensure Errors include their interesting non-enumerable members
if (value instanceof Error) {
return {
...value,
name: value.name,
message: value.message
};
}
if (key === "_headersMap") {
return this.sanitizeHeaders(key, value as {});
} else if (key === "url") {
Expand Down

0 comments on commit 2e45647

Please sign in to comment.