Handling of custom or invalid status codes

Looking for guidance on the best way to handle things like invalid status codes. Currently matching on IllegalResponseException in order to gracefully recover when the client receives an invalid response code (IE: statusCode: 0). Without this, the client rejects the bad status code and bubbles an IllegalResponseException, and the exception it returns is not very specific with the message “Illegal response status code” and no additional details. Ideally in this scenario we would want to return a 502 - Bad Gateway, so reaching out to see if there is a less blanket approach to handling these kinds of invalid responses.