Skip to content

Commit

Permalink
Merge branch 'feature/poc-minimal-fix' into feature/poc
Browse files Browse the repository at this point in the history
  • Loading branch information
noemil12 committed Nov 23, 2023
2 parents 3849df2 + 250fc76 commit ce5c159
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum ExceptionTypeEnum {
CORRESPONDENCE_NOT_FOUND("CORRESPONDENCE_NOT_FOUND", "Non risulta corrispondenza tra l'erogatore e l'id del servizio: "),
JWT_NOT_VALID("JWT_NOT_VALID", "Il voucher passato non è valido"),
JWT_UNAUTHORIZED("JWT_UNAUTHORIZED", "Il voucher passato non è autorizzato a procedere"),
UNAUTHORIZED("NOT_AUTHORIZED", "User not authorized"),
JWT_TYPE_INCORRECT("JWT_TYPE_INCORRECT", "Il voucher passato non è del tipo atteso"),
JWT_EMPTY("JWT_EMPTY", "Il voucher passato è vuoto"),
JWT_NOT_PRESENT("JWT_NOT_PRESENT", "Il voucher non è stato passato"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
import it.pagopa.interop.signalhub.push.service.dto.Problem;
import it.pagopa.interop.signalhub.push.service.dto.ProblemError;
import it.pagopa.interop.signalhub.push.service.mapper.ProblemErrorMapper;
import it.pagopa.interop.signalhub.push.service.mapper.SignalMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.ControllerAdvice;
Expand All @@ -37,9 +34,20 @@ public Mono<ResponseEntity<Problem>> handle(JsonMappingException exception) {
log.error("Returning HTTP 400 Bad Request {}", exception.getMessage());
final Problem problem = new Problem();
problem.setTitle(HttpStatus.BAD_REQUEST.name());
problem.setDetail(exception.getCause().getMessage());
problem.setDetail(HttpStatus.valueOf(HttpStatus.BAD_REQUEST.value()).getReasonPhrase());
problem.setStatus(HttpStatus.BAD_REQUEST.value());

ProblemError problemError= new ProblemError();
problemError.setCode("INVALID_INPUT");

if(exception.getCause()!= null) problemError.setDetail(exception.getCause().getMessage());
else problemError.setDetail(exception.getMessage());

List<ProblemError> errors= new ArrayList<>();
errors.add(problemError);

problem.setErrors(errors);

return Mono.just(ResponseEntity.status(HttpStatus.BAD_REQUEST.value()).body(problem));

}
Expand All @@ -61,7 +69,7 @@ public Mono<ResponseEntity<Problem>> handleResponseEntityException(final WebExch

List<ProblemError> errors= new ArrayList<>();
for(FieldError error : exception.getFieldErrors()) {
errors.add(problemErrorMapper.toEvent(error));
errors.add(problemErrorMapper.toProblemError(error));
}

final Problem problem = new Problem();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package it.pagopa.interop.signalhub.push.service.mapper;

import it.pagopa.interop.signalhub.push.service.dto.ProblemError;
import it.pagopa.interop.signalhub.push.service.dto.Signal;
import it.pagopa.interop.signalhub.push.service.dto.SignalRequest;
import it.pagopa.interop.signalhub.push.service.queue.model.SignalEvent;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.springframework.validation.FieldError;
Expand All @@ -13,7 +10,7 @@ public interface ProblemErrorMapper {

@Mapping(target = "code", source= "signal.field")
@Mapping(target = "detail", source= "signal.defaultMessage")
ProblemError toEvent(FieldError signal);
ProblemError toProblemError(FieldError signal);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class SignalServiceImpl implements SignalService {
@Override
public Mono<Signal> pushSignal(String producerId, SignalRequest signalRequest) {
return organizationEService.getEService(signalRequest.getEserviceId(), producerId)
.switchIfEmpty(Mono.error(new PDNDGenericException(ExceptionTypeEnum.CORRESPONDENCE_NOT_FOUND, ExceptionTypeEnum.CORRESPONDENCE_NOT_FOUND.getMessage().concat(signalRequest.getEserviceId()), HttpStatus.FORBIDDEN)))
.switchIfEmpty(Mono.error(new PDNDGenericException(ExceptionTypeEnum.UNAUTHORIZED, ExceptionTypeEnum.UNAUTHORIZED.getMessage(), HttpStatus.FORBIDDEN)))
.flatMap(eservice -> signalRepository.findBySignalIdAndEServiceId(signalRequest.getSignalId(), signalRequest.getEserviceId()))
.flatMap(eservice -> {
log.debug("eservice = {}, SIGNALID_ALREADY_EXISTS", eservice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void whenCallPushSignalAndCorrespondenceNotFound() {
StepVerifier.create(signalService.pushSignal("1234", signalRequest))
.expectErrorMatches((ex) -> {
assertTrue(ex instanceof PDNDGenericException);
assertEquals(ExceptionTypeEnum.CORRESPONDENCE_NOT_FOUND, ((PDNDGenericException) ex).getExceptionType());
assertEquals(ExceptionTypeEnum.UNAUTHORIZED, ((PDNDGenericException) ex).getExceptionType());
return true;
}).verify();
}
Expand Down

0 comments on commit ce5c159

Please sign in to comment.