Harmonize JSON API error messages
This commit is contained in:
+9
-8
@@ -10,8 +10,8 @@ export default class Api {
|
||||
}
|
||||
|
||||
async get(sAction, asParams = {}) {
|
||||
const response = await this.request(sAction, asParams, 'GET');
|
||||
return response.data;
|
||||
const oResponse = await this.request(sAction, asParams, 'GET');
|
||||
return oResponse.data;
|
||||
}
|
||||
|
||||
async getAsset(sAssetPath) {
|
||||
@@ -25,8 +25,8 @@ export default class Api {
|
||||
}
|
||||
|
||||
async post(sAction, asParams = {}) {
|
||||
const response = await this.request(sAction, asParams, 'POST');
|
||||
return response.data;
|
||||
const oResponse = await this.request(sAction, asParams, 'POST');
|
||||
return oResponse.data;
|
||||
}
|
||||
|
||||
async request(sAction, asParams = {}, method = 'GET') {
|
||||
@@ -59,12 +59,13 @@ export default class Api {
|
||||
}
|
||||
|
||||
const oResponse = await oRequest.json();
|
||||
oResponse.descKey = this.lang.getLangKey(oResponse.desc);
|
||||
oResponse.desc = this.lang.parse(oResponse.desc);
|
||||
oResponse.desc_lang_text = this.lang.get(oResponse.desc_lang_id, oResponse.desc_lang_params);
|
||||
|
||||
if(oResponse.result == this.errorCode) {
|
||||
const oError = new Error(oResponse.desc);
|
||||
oError.descKey = oResponse.descKey;
|
||||
const oError = new Error(oResponse.desc_lang_text);
|
||||
oError.desc_lang_id = oResponse.desc_lang_id;
|
||||
oError.desc_lang_params = oResponse.desc_lang_params;
|
||||
oError.desc_lang_text = oResponse.desc_lang_text;
|
||||
throw oError;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user