feat: adding try catch

This commit is contained in:
caturbgs
2021-12-16 22:40:21 +07:00
parent 2acf3c9d5e
commit a62315641a
11 changed files with 385 additions and 194 deletions

View File

@@ -25,26 +25,38 @@ export class Partner {
}
async getData() {
const response = await http.get(`/users/partner?page=${this.page}&pageSize=${this.pageSize}`);
this.data = response.body.data.map((item, idx) => {
item.key = idx;
return item
}) ?? []
try {
const response = await http.get(`/users/partner?page=${this.page}&pageSize=${this.pageSize}`);
this.total_data = response.body.count ?? 0
this.data = response.body.data.map((item, idx) => {
item.key = idx;
return item
}) ?? []
this.total_data = response.body.count ?? 0
} catch (e) {
console.error(e);
}
}
async create(data) {
const response = await http.post('/users/partner').send(data);
await this.getData();
return response;
try {
const response = await http.post('/users/partner').send(data);
await this.getData();
return response;
} catch (e) {
console.error(e);
}
}
async update(id, data) {
const response = await http.put(`/users/partner/${id}`).send(data);
await this.getData();
return response;
try {
const response = await http.put(`/users/partner/${id}`).send(data);
await this.getData();
return response;
} catch (e) {
console.error(e);
}
}
// async updateStatus(id, data) {
@@ -54,15 +66,23 @@ export class Partner {
// }
async delete(id) {
const response = await http.del(`/product/${id}`);
await this.getData();
return response;
try {
const response = await http.del(`/product/${id}`);
await this.getData();
return response;
} catch (e) {
console.error(e);
}
}
async changeStatus(id, status) {
const response = await http.get(`/users/partner/${id}/${status}`);
await this.getData();
return response;
try {
const response = await http.get(`/users/partner/${id}/${status}`);
await this.getData();
return response;
} catch (e) {
console.error(e);
}
}
}