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,42 +25,62 @@ export class Subcategory {
}
async getData() {
const response = await http.get(`/product/sub-categories?page=${this.page}&pageSize=${this.pageSize}`);
this.data = response.body.data.map((item, idx) => {
try {
const response = await http.get(`/product/sub-categories?page=${this.page}&pageSize=${this.pageSize}`);
this.data = response.body.data.map((item, idx) => {
item.key = idx;
item.categoryName = item.category.name;
return item
}) ?? []
this.total_data = response.body.total_data ?? 0
this.total_data = response.body.total_data ?? 0
} catch (e) {
console.error(e);
}
}
async getDataSubCategories() {
const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`);
this.dataSubCategories = response.body.data.map((item, idx) => {
try {
const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`);
this.dataSubCategories = response.body.data.map((item, idx) => {
item.key = idx;
return item
}) ?? []
this.total_dataSubCategories = response.body.count ?? 0
this.total_dataSubCategories = response.body.count ?? 0
} catch (e) {
console.error(e);
}
}
async create(data) {
const response = await http.post('/product/sub-categories').send(data);
await this.getData();
return response;
try {
const response = await http.post('/product/sub-categories').send(data);
await this.getData();
return response;
} catch (e) {
console.error(e);
}
}
async update(id, data) {
const response = await http.put(`/product/sub-categories/${id}`).send(data);
await this.getData();
return response;
try {
const response = await http.put(`/product/sub-categories/${id}`).send(data);
await this.getData();
return response;
} catch (e) {
console.error(e);
}
}
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);
}
}
}