FIX: try catch in customer controller

This commit is contained in:
marcos-silva-rodrigues
2025-01-06 14:15:29 -03:00
parent 3a6054c1c6
commit 8c12291096
2 changed files with 24 additions and 21 deletions
+14 -2
View File
@@ -59,9 +59,21 @@ export class CustomersController {
this.logger.info('saveCustomertheme', JSON.stringify({
id, theme: data
}));
const theme = await this.customersService.createThemeByCustomer(id, data);
return theme;
try {
// const theme = await this.customersService.createThemeByCustomer(id, data);
this.logger.info('saveCustomertheme', JSON.stringify(data));
return { theme: null };
} catch (err) {
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
this.logger.error('Error - saveCustomertheme - Expect CUSTOMER.NOT_FOUND');
throw new HttpException(err.details, HttpStatus.NOT_FOUND);
} else {
this.logger.error('Error - saveCustomertheme Unknown Error:' + err?.message);
return { theme: null };
};
}
}
@Get(':id/theme')
+10 -19
View File
@@ -96,32 +96,23 @@ export class CustomersService implements OnModuleInit {
throw new HttpException(null, HttpStatus.BAD_REQUEST);
}
try {
const result = await firstValueFrom(
this.customerService.CustomerCreateTheme({
customerId: id,
theme
}),
);
return { theme: result };
} catch (err) {
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
this.logger.error('Error - saveCustomertheme - Expect CUSTOMER.NOT_FOUND');
throw new HttpException(err.details, HttpStatus.NOT_FOUND);
} else {
this.logger.error('Error - saveCustomertheme Unknown Error:' + err?.message);
throw err
};
}
const result = await firstValueFrom(
this.customerService.CustomerCreateTheme({
customerId: id,
theme
}),
);
return { theme: result };
}
async getThemeByCustomer(id: string): Promise<CustomerThemeResponse> {
async getThemeByCustomer(id: string): Promise<CustomerThemeResponse> {
if (!id) {
this.logger.error('Error - getCustomerTheme - not found id:' + id);
throw new HttpException(null, HttpStatus.BAD_REQUEST);
}
const result = await firstValueFrom(
const result = await firstValueFrom(
this.customerService.CustomerGetTheme({
id
}),