Skip to content

Commit

Permalink
fix: handle invalid HttpIn pipeline request (#514)
Browse files Browse the repository at this point in the history
Co-authored-by: Yalz <[email protected]>
  • Loading branch information
Yalz and Yalz authored Feb 27, 2024
1 parent 2886f04 commit 55108b7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public class PipelineExceptionHandler extends ResponseEntityExceptionHandler {
public ResponseEntity<Object> handleConflict(RuntimeException ex, WebRequest request) {
return handleExceptionInternal(ex, ex.getMessage(), new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
}

@ExceptionHandler(value = {PipelineDoesNotExistException.class})
public ResponseEntity<Object> handleNotFound(RuntimeException ex, WebRequest request) {
return handleExceptionInternal(ex, ex.getMessage(), new HttpHeaders(), HttpStatus.NOT_FOUND, request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package be.vlaanderen.informatievlaanderen.ldes.ldio.exception;

public class PipelineDoesNotExistException extends PipelineException {
private final String pipeline;

public PipelineDoesNotExistException(String pipeline) {
this.pipeline = pipeline;
}

@Override
public String getMessage() {
return "Pipeline \"%s\": No pipeline like that exists".formatted(pipeline);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import be.vlaanderen.informatievlaanderen.ldes.ldio.event.HttpInPipelineCreatedEvent;
import be.vlaanderen.informatievlaanderen.ldes.ldio.events.PipelineDeletedEvent;
import be.vlaanderen.informatievlaanderen.ldes.ldio.exception.PipelineDoesNotExistException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.EventListener;
Expand Down Expand Up @@ -29,7 +30,7 @@ ResponseEntity<String> processInput(@RequestHeader("Content-Type") String conten
logIncomingRequest(contentType, contentLength, pipeline);

ofNullable(httpInProcesses.get(pipeline))
.orElseThrow(() -> new IllegalArgumentException("Not a valid pipeline"))
.orElseThrow(() -> new PipelineDoesNotExistException(pipeline))
.processInput(content, contentType);
return ResponseEntity.accepted().build();
}
Expand Down

0 comments on commit 55108b7

Please sign in to comment.