mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-21 07:19:09 +00:00
FIX: try catch in customer controller
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user