[FIX] REST for method calls not raising errors (#2408)

* [FIX] REST for Method calls not raising erorrs

* Remove unnecessary lint disable
This commit is contained in:
Diego Mello 2020-08-19 14:13:02 -03:00 committed by GitHub
parent 8841d17a44
commit 6555687891
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -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) {
return new Promise(async(resolve, reject) => {
const data = await this.post(`method.call/${ method }`, { message: JSON.stringify({ method, params }) });
const { result } = JSON.parse(data.message);
return result;
const response = JSON.parse(data.message);
if (response?.error) {
return reject(response.error);
}
return resolve(response.result);
});
}
return this.methodCall(method, ...params);
},