public static HttpResponseMessage SetStatus( this HttpResponseMessage responseMessage, IEnumerable <IResponseStatus> responseStatus, ActionDescriptor actionDescriptor, ResponseState responseState, string errorMessage) { var context = new ResponseStatusContext(responseMessage, responseState, errorMessage); actionDescriptor.ResponseStatus.ThatAppliesToOrDefault( responseStatus, context)?.SetStatus(context); return(responseMessage); }
public virtual void SetStatus(ResponseStatusContext context) { switch (context.ResponseState) { case ResponseState.NoReader: SetStatus <NoReaderStatusAttribute>(context.ResponseMessage, _configuration.DefaultNoReaderStatusCode, _configuration.DefaultNoReaderReasonPhrase); break; case ResponseState.BindingFailure: SetStatus <BindingFailureStatusAttribute>(context.ResponseMessage, _configuration.DefaultBindingFailureStatusCode, _configuration.DefaultBindingFailureReasonPhrase? .Invoke(context.ErrorMessage)); break; case ResponseState.HasResponse: SetStatus <HasResponseStatusAttribute>(context.ResponseMessage, _configuration.DefaultHasResponseStatusCode, _configuration.DefaultHasResponseReasonPhrase); break; case ResponseState.NoResponse: SetStatus <NoResponseStatusAttribute>(context.ResponseMessage, _configuration.DefaultNoResponseStatusCode, _configuration.DefaultNoResponseReasonPhrase); break; case ResponseState.NoWriter: SetStatus <NoWriterStatusAttribute>(context.ResponseMessage, _configuration.DefaultNoWriterStatusCode, _configuration.DefaultNoWriterReasonPhrase); break; } }
public virtual bool AppliesTo(ResponseStatusContext context) { return(true); }