mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-03-10 20:41:44 +00:00
Refactor error handling in DeviceService
This commit is contained in:
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user