From ca1df5ee71bbb2845ea04fba37cf1444a9277255 Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 16 Jan 2024 12:04:55 +0000 Subject: [PATCH] FIx `appendErrorToOutput()` overwriting warnings instead of appending --- project/src/utils/HttpResponseUtil.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/project/src/utils/HttpResponseUtil.ts b/project/src/utils/HttpResponseUtil.ts index 307d8949..26c532e8 100644 --- a/project/src/utils/HttpResponseUtil.ts +++ b/project/src/utils/HttpResponseUtil.ts @@ -68,13 +68,31 @@ export class HttpResponseUtil return this.getBody([]); } + /** + * Add an error into the 'warnings' array of the client response message + * @param output IItemEventRouterResponse + * @param message Error message + * @param errorCode Error code + * @returns IItemEventRouterResponse + */ public appendErrorToOutput( output: IItemEventRouterResponse, message = this.localisationService.getText("http-unknown_error"), errorCode = BackendErrorCodes.NONE, ): IItemEventRouterResponse { - output.warnings = [{ index: 0, errmsg: message, code: errorCode.toString() }]; + if (output.warnings?.length > 0) + { + output.warnings.push({ + index: output.warnings?.length - 1, + errmsg: message, + code: errorCode.toString() + }) + } + else + { + output.warnings = [{ index: 0, errmsg: message, code: errorCode.toString() }]; + } return output; }