mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 14:57:54 +00:00
Refactor error handling in controllers and services
This commit is contained in:
@@ -25,8 +25,8 @@ import { UpdateFloorNameDto } from '../dtos/update.floor.dto';
|
||||
export class FloorController {
|
||||
constructor(private readonly floorService: FloorService) {}
|
||||
|
||||
// @ApiBearerAuth()
|
||||
// @UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post()
|
||||
async addFloor(@Body() addFloorDto: AddFloorDto) {
|
||||
try {
|
||||
@@ -35,7 +35,7 @@ export class FloorController {
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -48,14 +48,10 @@ export class FloorController {
|
||||
const floor = await this.floorService.getFloorByUuid(floorUuid);
|
||||
return floor;
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
throw new HttpException('Floor not found', HttpStatus.NOT_FOUND);
|
||||
} else {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,14 +69,10 @@ export class FloorController {
|
||||
);
|
||||
return floor;
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
throw new HttpException('Floor not found', HttpStatus.NOT_FOUND);
|
||||
} else {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@@ -91,14 +83,10 @@ export class FloorController {
|
||||
const floor = await this.floorService.getFloorParentByUuid(floorUuid);
|
||||
return floor;
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
throw new HttpException('Floor not found', HttpStatus.NOT_FOUND);
|
||||
} else {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,14 +104,10 @@ export class FloorController {
|
||||
);
|
||||
return floor;
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
throw new HttpException('Floor not found', HttpStatus.NOT_FOUND);
|
||||
} else {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user