Skip to content

Commit

Permalink
fix(api): oversight in xforms and fo standard controllers (#853)
Browse files Browse the repository at this point in the history
* refactor(api): add logging on unhandled exceptions

* fix(api): oversight in xforms and fo standard controllers

* chore: bump version
  • Loading branch information
nsenave authored Jan 10, 2024
1 parent bedcf03 commit 3e68d0d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tasks.withType(JavaCompile).configureEach {

allprojects {
group = 'fr.insee.eno'
version = '3.15.2'
version = '3.15.3'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ public Mono<Void> generateXforms(
ServerHttpRequest request, ServerHttpResponse response) {
if (Context.HOUSEHOLD.equals(context))
return Mono.error(new ContextException("Xforms format is not compatible with 'HOUSEHOLD' context."));
return metadata.hasElement()
metadata.hasElement()
.flatMap(hasElementValue -> {
if (Context.BUSINESS.equals(context) && Boolean.FALSE.equals(hasElementValue))
return Mono.error(new MetadataFileException(
"The metadata file is required in 'BUSINESS' context."));
return passThrough.passePlatPost(request, response);
return null;
});
return passThrough.passePlatPost(request, response);
}

@Operation(
Expand All @@ -114,13 +115,14 @@ public Mono<Void> generateFO(
@RequestParam(value="Capture", required=false) CaptureEnum capture,
@PathVariable Context context,
ServerHttpRequest request, ServerHttpResponse response) {
return metadata.hasElement()
metadata.hasElement()
.flatMap(hasElementValue -> {
if (Context.BUSINESS.equals(context) && Boolean.FALSE.equals(hasElementValue))
return Mono.error(new MetadataFileException(
"The metadata file is required in 'BUSINESS' context."));
return passThrough.passePlatPost(request, response);
return null;
});
return passThrough.passePlatPost(request, response);
}

@Operation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import fr.insee.eno.legacy.exception.EnoLegacyParametersException;
import fr.insee.eno.treatments.exceptions.SpecificTreatmentsDeserializationException;
import fr.insee.eno.treatments.exceptions.SpecificTreatmentsValidationException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;


@ControllerAdvice
@Slf4j
public class EnoExceptionController {

@ExceptionHandler(value = EnoLegacyParametersException.class)
Expand Down Expand Up @@ -59,6 +61,7 @@ public ResponseEntity<Object> exception(SpecificTreatmentsValidationException ex

@ExceptionHandler(value = Exception.class)
public ResponseEntity<Object> exception(Exception exception) {
log.error("Unhandled exception thrown in controller: ", exception);
return new ResponseEntity<>("Unknown error during generation: "+exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}

Expand Down

0 comments on commit 3e68d0d

Please sign in to comment.