Skip to content

Commit

Permalink
fixes networknt#1631 update request transformer to do some validation…
Browse files Browse the repository at this point in the history
… logic (networknt#1632)
  • Loading branch information
stevehu committed Feb 28, 2023
1 parent ff364f2 commit f8b13e9
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

/**
* Transforms the request body of an active request being processed.
* This is executed by RequestInterceptorExecutionHandler.
* This is executed by RequestInterceptorExecutionHandler. Also, this class will be responsible for
* some special validations that the normal handlers cannot do or not easy to do.
*
* @author Kalev Gonvick
*
Expand Down Expand Up @@ -204,6 +205,17 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
}
exchange.getRequestHeaders().put(Headers.CONTENT_LENGTH, length);
break;
case "validationError":
// If the rule engine returns any validationError entry, stop the chain and send the res.
// this can be either XML or JSON or TEXT. Just make sure it matches the content type
String errorMessage = (String)result.get("errorMessage");
String contentType = (String)result.get("contentType");
int statusCode = (Integer)result.get("statusCode");
if(logger.isTraceEnabled()) logger.trace("Entry key validationError with errorMessage {} contentType {} statusCode {}");
exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, contentType);
exchange.setStatusCode(statusCode);
exchange.getResponseSender().send(errorMessage);
break;
}
}
}
Expand Down

0 comments on commit f8b13e9

Please sign in to comment.