feat: adding try catch
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user