swagger 即使未找到对象也会返回 403 错误

问题描述 投票:0回答:1
`@PostMapping("/insert")
@Operation(summary = "Создать раздел и подразделы")
@SecurityRequirement(name = "Bearer Authentication")
@ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "Раздел/подраздел успешно создан/обновлен"),
        @ApiResponse(responseCode = "401", description = "Требуется авторизация"),
        @ApiResponse(responseCode = "400", description = "Не найден объект", content = {@Content(schema = @Schema(implementation = ExceptionDto.class))}),
        @ApiResponse(responseCode = "500", description = "Внутренняя ошибка", content = {@Content(schema = @Schema(implementation = ExceptionDto.class))})})
public List<Section> insert(@RequestBody @Validated @NotNull Section dto) {
    return sectionService.insertSection(dto);
}

@Transactional
public Section insertSection(@NotNull Section dto) {
    if (dto.getId() != null && (!sectionRepository.existsById(dto.getId()))) {
        throw new EntityNotFoundException("Section not found");
    }
    UUID uuid = UUID.randomUUID();
    Section section = new Section();
    section.setId(dto.getId());
    section.setCode(uuid.toString());
    section.setSectionName(dto.getSectionName());
    return sectionRepository.save(section);
}`

为什么swagger会抛出403错误?在应用程序日志中,它表示找不到该部分。如何让swagger显示这个错误

ExceptionDto.class <- RuntimeException

我尝试将 400、403、404 错误放入错误中

spring spring-boot rest swagger
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.