import {getDB} from '../db/db';
import {createAccount, createAccountReceiver} from '../wasm/func';
-import {handleAxiosError} from '../utils/http';
-
+import {handleApiError, handleAxiosError} from '../utils/http';
function accountsSDK(bytom){
this.http = bytom.serverHttp;
this.bytom = bytom;
pm.label = label;
}
this.http.request('account/new-address', pm, net).then(resp => {
+ if (resp.status !== 200) {
+ reject(handleApiError(resp));
+ return;
+ }
let dbData = resp.data.data;
dbData.guid = guid;
dbData.net = net;
pm.label = label;
}
that.http.request('account/create', pm, net).then(resp => {
+ if (resp.status !== 200) {
+ reject(handleApiError(resp));
+ return;
+ }
let dbData = resp.data.data;
dbData.rootXPub = rootXPub;
dbData.alias = alias;
import { signTransaction1 } from '../wasm/func';
-import { handleAxiosError } from '../utils/http';
+import { handleApiError, handleAxiosError } from '../utils/http';
import { getDB } from '../db/db';
function transactionSDK(bytom) {
if (address) {
pm.address = address;
}
+ let url = 'merchant/list-transactions';
+ let args = new URLSearchParams();
if (typeof start !== 'undefined') {
- pm.start = start;
+ args.append('start', start);
}
if (limit) {
- pm.limit = limit;
+ args.append('limit', limit);
}
- this.http.request('merchant/list-transactions', pm, net).then(resp => {
+ url = url + '?' + args.toString();
+ this.http.request(url, pm, net).then(resp => {
resolve(resp.data);
}).catch(err => {
reject(handleAxiosError(err));
let retPromise = new Promise((resolve, reject) => {
let pm = {guid: guid, raw_transaction: raw_transaction, signatures: signatures};
this.http.request('merchant/submit-payment', pm, net).then(resp => {
+ if (resp.status !== 200) {
+ reject(handleApiError(resp));
+ return;
+ }
resolve(resp.data);
}).catch(err => {
reject(handleAxiosError(err));
pm.fee = fee;
}
this.http.request('merchant/build-payment', pm, net).then(resp => {
+ if (resp.status !== 200) {
+ reject(handleApiError(resp));
+ return;
+ }
resolve(resp.data);
}).catch(err => {
reject(handleAxiosError(err));
export function handleAxiosError(error) {
- if (error.response) {
+ if (error.response && error.response.data.hasOwnProperty('error')) {
return new Error(error.response.data.error);
} else {
- return error;
+ return error;
+ }
+}
+
+export function handleApiError(response) {
+ if (response.data.hasOwnProperty('error')) {
+ return new Error(response.data.error);
+ } else {
+ return new Error('Unknow error');
}
}
\ No newline at end of file