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

@@ -20,55 +20,78 @@ export class Category {
}
async getData() {
const response = await http.get(`/product/categories?page=${this.page}&pageSize=${this.pageSize}`);
this.data = response.body.data.map((item, idx) => {
try {
const response = await http.get(`/product/categories?page=${this.page}&pageSize=${this.pageSize}`);
this.data = response.body.data .map((item, idx) => {
item.key = idx;
return item
}) ?? []
this.total_data = response.body.total_data ?? 0
this.total_data = response.body.total_data ?? 0
} catch (e) {
console.log(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.log(e);
}
}
async getDataCategories() {
const response = await http.get(`/product/categories?page=${this.pageCategories}&pageSize=${this.pageSizeCategories}`);
try {
const response = await http.get(`/product/categories?page=${this.pageCategories}&pageSize=${this.pageSizeCategories}`);
this.dataCategories = response.body.data.map((item, idx) => {
item.key = idx;
return item
}) ?? []
this.total_dataCategories = response.body.total_data ?? 0
if (this.dataCategories.length > 0) {
this.filterCategory = this.dataCategories[0].id
this.dataCategories = response.body.data.map((item, idx) => {
item.key = idx;
return item
}) ?? []
this.total_dataCategories = response.body.total_data ?? 0
if (this.dataCategories.length > 0) {
this.filterCategory = this.dataCategories[0].id
}
} catch (e) {
console.error(e);
}
}
async create(data) {
const response = await http.post('/product/categories').send(data);
await this.getData();
return response;
try {
const response = await http.post('/product/categories').send(data);
await this.getData();
return response;
} catch (e) {
console.log(e);
}
}
async update(id, data) {
const response = await http.put(`/product/categories/${id}`).send(data);
await this.getData();
return response;
try {
const response = await http.put(`/product/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);
}
}
}