I have a flow that returns and empty array when a user is searched for but does not exist. I am using a raise custom error to send an error that can be used by the error handling.
We have moved to a common error handling design so ideally the custom error should map to a HTTP:NOT_FOUND but I don't want to update the common handler in this case.
Is there any way to either update or "throw" a 404 from lower level error handling that could be picked up by the error handling in the main APIkit?
Shekh Muenuddeen (NTTData) Forum Ambassador
Hey,
HTTP Listener in the error response section we have HTTP Status, so defined the one variable there and always put HTTP Status code, so when error response return back to the consumer so HTTP status will also be send back to the consumer.
I have created DataWeave module for getting HTTP Status code for error type, based on error namespace and error identifier :)
DataWeave Module
fun getHttpStatusCode(errorNamespace : String, errorType: String) =
(
errorNamespace match {
case "HTTP" -> httpErrorHttpStatus(errorType)
else -> 500
}
)
fun httpErrorHttpStatus(errorType: String) =
(
errorType match
{
case "BASIC_AUTHENTICATION" -> "400"
case "BAD_REQUEST" -> "400"
case "CLIENT_SECURITY" -> "403"
case "CONNECTIVITY" -> "503"
case "FORBIDDEN" -> "403"
case "INTERNAL_SERVER_ERROR" -> "500"
case "METHOD_NOT_ALLOWED" -> "405"
case "NOT_ACCEPTABLE" -> "406"
case "NOT_FOUND" -> "404"
case "PARSING" -> "400"
case "RETRY_EXHAUSTED" -> "503"
case "SECURITY" -> "401"
case "TIMEOUT" -> "504"
case "TOO_MANY_REQUESTS" -> "429"
case "UNAUTHORIZED" -> "401"
case "UNSUPPORTED_MEDIA_TYPE" -> "415"
case "SERVICE_UNAVAILABLE" -> "503"
else -> "500"
}
)
DataWeave code to call this modules
%dw 2.0
import modules::httpStatusMapper
output application/java
---
httpStatusMapper::getHttpStatusCode(
error.errorType.namespace as String,
error.errorType.identifier as String
)