From 8504ec6c4d7c38e2a1e243c5fc7790a457f5553a Mon Sep 17 00:00:00 2001 From: Mihajlo Medjedovic Date: Tue, 15 Sep 2020 13:18:26 +0200 Subject: [PATCH] fix: error response stringify and added raw field --- src/types/ErrorResponse.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/types/ErrorResponse.ts b/src/types/ErrorResponse.ts index 1f88c8f..d0ff0e0 100644 --- a/src/types/ErrorResponse.ts +++ b/src/types/ErrorResponse.ts @@ -2,14 +2,25 @@ export class ErrorResponse { body: ErrorBody constructor(message: string, details?: any) { + let detailsString = ''; + let raw + + try { + detailsString = JSON.stringify(details) + } catch { + raw = details + } + this.body = { message, - details + details: detailsString, + raw } } } interface ErrorBody { message: string - details: any + details: string, + raw: any }