Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BadUserInput results to 400 response code. #307

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package madgik.exareme.master.gateway.async.handler.HBP.Exceptions;

public class RequestException extends Exception {
public RequestException(String algorithmName, String message) {
public class BadRequestException extends Exception {
public BadRequestException(String algorithmName, String message) {
super(message + " Algorithm: " + algorithmName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import madgik.exareme.master.engine.iterations.handler.NIterativeAlgorithmResultEntity;
import madgik.exareme.master.engine.iterations.state.IterativeAlgorithmState;
import madgik.exareme.master.gateway.ExaremeGatewayUtils;
import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.BadRequestException;
import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.BadUserInputException;
import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.RequestException;
import madgik.exareme.master.gateway.async.handler.entity.NQueryResultEntity;
import madgik.exareme.master.queryProcessor.HBP.AlgorithmProperties;
import madgik.exareme.master.queryProcessor.HBP.Algorithms;
Expand Down Expand Up @@ -101,7 +101,7 @@ private void handleHBPAlgorithmExecution(HttpRequest request, HttpResponse respo
String algorithmName = getAlgorithmName(request);
AlgorithmProperties algorithmProperties = Algorithms.getInstance().getAlgorithmProperties(algorithmName);
if (algorithmProperties == null)
throw new RequestException(algorithmName, "The algorithm '" + algorithmName + "' does not exist.");
throw new BadRequestException(algorithmName, "The algorithm '" + algorithmName + "' does not exist.");

String algorithmKey = algorithmName + "_" + System.currentTimeMillis();

Expand Down Expand Up @@ -168,13 +168,7 @@ private void handleHBPAlgorithmExecution(HttpRequest request, HttpResponse respo
response.setStatusCode(HttpStatus.SC_OK);
response.setEntity(entity);
}
} catch (BadUserInputException e) {
log.error(e.getMessage());
String errorType = HBPQueryHelper.ErrorResponse.ErrorResponseTypes.user_error;
response.setStatusCode(HttpStatus.SC_OK);
response.setEntity(createErrorResponseEntity(e.getMessage(), errorType));

} catch (RequestException e) {
} catch (BadUserInputException | BadRequestException e) {
log.error(e.getMessage());
String errorType = HBPQueryHelper.ErrorResponse.ErrorResponseTypes.user_error;
response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import madgik.exareme.master.engine.AdpDBManager;
import madgik.exareme.master.engine.AdpDBManagerLocator;
import madgik.exareme.master.gateway.ExaremeGatewayUtils;
import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.RequestException;
import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.BadRequestException;
import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.BadUserInputException;
import madgik.exareme.master.gateway.async.handler.entity.NQueryResultEntity;
import madgik.exareme.master.queryProcessor.HBP.AlgorithmProperties;
Expand Down Expand Up @@ -55,7 +55,7 @@ public void handle(
HttpResponse response = httpexchange.getResponse();
try {
handleInternal(request, response, context);
} catch (AlgorithmException | CDEsMetadataException | ComposerException | BadUserInputException | RequestException e) {
} catch (AlgorithmException | CDEsMetadataException | ComposerException | BadUserInputException | BadRequestException e) {
e.printStackTrace();
}
httpexchange.submitResponse(new BasicAsyncResponseProducer(response));
Expand All @@ -65,7 +65,7 @@ private void handleInternal(
final HttpRequest request,
final HttpResponse response,
final HttpContext context
) throws HttpException, IOException, AlgorithmException, CDEsMetadataException, ComposerException, BadUserInputException, RequestException {
) throws HttpException, IOException, AlgorithmException, CDEsMetadataException, ComposerException, BadUserInputException, BadRequestException {

String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) {
Expand Down Expand Up @@ -97,7 +97,7 @@ private void handleInternal(
AlgorithmProperties algorithmProperties = Algorithms.getInstance().getAlgorithmProperties(algorithmName);

if (algorithmProperties == null)
throw new RequestException(algorithmName, "The algorithm does not exist.");
throw new BadRequestException(algorithmName, "The algorithm does not exist.");

algorithmProperties.mergeWithAlgorithmParameters(inputContent);

Expand Down