diff --git a/src/device/services/device.service.ts b/src/device/services/device.service.ts index ee7a911..d4c2a2b 100644 --- a/src/device/services/device.service.ts +++ b/src/device/services/device.service.ts @@ -125,9 +125,15 @@ export class DeviceService { return { message: 'device added in room successfully' }; } catch (error) { if (error.code === '23505') { - throw new Error('Device already exists in the room.'); + throw new HttpException( + 'Device already exists in the room', + HttpStatus.BAD_REQUEST, + ); } else { - throw new Error('Failed to add device in room'); + throw new HttpException( + 'Failed to add device in room', + HttpStatus.INTERNAL_SERVER_ERROR, + ); } } } @@ -141,9 +147,15 @@ export class DeviceService { return { message: 'device added in group successfully' }; } catch (error) { if (error.code === '23505') { - throw new Error('Device already exists in the group.'); + throw new HttpException( + 'Device already exists in the group', + HttpStatus.BAD_REQUEST, + ); } else { - throw new Error('Failed to add device in group'); + throw new HttpException( + 'Failed to add device in group', + HttpStatus.INTERNAL_SERVER_ERROR, + ); } } }