From 65556878913f6ee89a0e52fff84dda10d4796731 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 19 Aug 2020 14:13:02 -0300 Subject: [PATCH] [FIX] REST for method calls not raising errors (#2408) * [FIX] REST for Method calls not raising erorrs * Remove unnecessary lint disable --- app/lib/rocketchat.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 52c09f93f..dac3a3786 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -754,12 +754,17 @@ const RocketChat = { return this.methodCallWrapper('getUsersOfRoom', rid, allUsers, { skip, limit }); }, - async methodCallWrapper(method, ...params) { + methodCallWrapper(method, ...params) { const { API_Use_REST_For_DDP_Calls } = reduxStore.getState().settings; if (API_Use_REST_For_DDP_Calls) { - const data = await this.post(`method.call/${ method }`, { message: JSON.stringify({ method, params }) }); - const { result } = JSON.parse(data.message); - return result; + return new Promise(async(resolve, reject) => { + const data = await this.post(`method.call/${ method }`, { message: JSON.stringify({ method, params }) }); + const response = JSON.parse(data.message); + if (response?.error) { + return reject(response.error); + } + return resolve(response.result); + }); } return this.methodCall(method, ...params); },