I have implemented an IErrorHandler for my service witch needs to return 403 instead o 400 in case of wrong Authorization.
This is how my ProvideFault method looks like:
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
if (((FaultException)error).Code.SubCode.Name == "FailedAuthentication")
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription =
"StatusCode is forced to change in order to have the correct response on authentication.";
}
}
I wonder if there is any way to write a more nicer check for the error and its status code, or how to get an authorization exception not a FaultException witch is more general?. I don't find it nice to check after the FailedAuthentication string, and in fact its authorization not authentication...