HttpRequestMessageExtensions.CreateErrorResponse Method

Definition

Overloads

CreateErrorResponse(HttpRequestMessage, HttpStatusCode, ModelStateDictionary)

Helper method that performs content negotiation and creates a HttpResponseMessage representing an error with an instance of System.Net.Http.ObjectContent`1 wrapping an HttpError for model state modelState. If no formatter is found, this method returns a response with status 406 NotAcceptable.

CreateErrorResponse(HttpRequestMessage, HttpStatusCode, Exception)

Helper method that performs content negotiation and creates a HttpResponseMessage representing an error with an instance of System.Net.Http.ObjectContent`1 wrapping an HttpError for exception exception. If no formatter is found, this method returns a response with status 406 NotAcceptable.

CreateErrorResponse(HttpRequestMessage, HttpStatusCode, String)

Helper method that performs content negotiation and creates a HttpResponseMessage representing an error with an instance of System.Net.Http.ObjectContent`1 wrapping an HttpError with message message. If no formatter is found, this method returns a response with status 406 NotAcceptable.

CreateErrorResponse(HttpRequestMessage, HttpStatusCode, HttpError)

Helper method that performs content negotiation and creates a HttpResponseMessage representing an error with an instance of System.Net.Http.ObjectContent`1 wrapping error as the content. If no formatter is found, this method returns a response with status 406 NotAcceptable.

CreateErrorResponse(HttpRequestMessage, HttpStatusCode, String, Exception)

Helper method that performs content negotiation and creates a HttpResponseMessage representing an error with an instance of System.Net.Http.ObjectContent`1 wrapping an HttpError with error message message for exception exception. If no formatter is found, this method returns a response with status 406 NotAcceptable.

CreateErrorResponse(HttpRequestMessage, HttpStatusCode, ModelStateDictionary)

Helper method that performs content negotiation and creates a HttpResponseMessage representing an error with an instance of System.Net.Http.ObjectContent`1 wrapping an HttpError for model state modelState. If no formatter is found, this method returns a response with status 406 NotAcceptable.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Net::Http::HttpResponseMessage ^ CreateErrorResponse(System::Net::Http::HttpRequestMessage ^ request, System::Net::HttpStatusCode statusCode, Microsoft::AspNetCore::Mvc::ModelBinding::ModelStateDictionary ^ modelState);
public static System.Net.Http.HttpResponseMessage CreateErrorResponse (this System.Net.Http.HttpRequestMessage request, System.Net.HttpStatusCode statusCode, Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary modelState);
static member CreateErrorResponse : System.Net.Http.HttpRequestMessage * System.Net.HttpStatusCode * Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary -> System.Net.Http.HttpResponseMessage
<Extension()>
Public Function CreateErrorResponse (request As HttpRequestMessage, statusCode As HttpStatusCode, modelState As ModelStateDictionary) As HttpResponseMessage

Parameters

request
HttpRequestMessage

The request.

statusCode
HttpStatusCode

The status code of the created response.

modelState
ModelStateDictionary

The model state.

Returns

HttpResponseMessage

An error response for modelState with status code statusCode.

Remarks

This method requires that request has been associated with an instance of HttpContext.

Applies to

CreateErrorResponse(HttpRequestMessage, HttpStatusCode, Exception)

Helper method that performs content negotiation and creates a HttpResponseMessage representing an error with an instance of System.Net.Http.ObjectContent`1 wrapping an HttpError for exception exception. If no formatter is found, this method returns a response with status 406 NotAcceptable.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Net::Http::HttpResponseMessage ^ CreateErrorResponse(System::Net::Http::HttpRequestMessage ^ request, System::Net::HttpStatusCode statusCode, Exception ^ exception);
public static System.Net.Http.HttpResponseMessage CreateErrorResponse (this System.Net.Http.HttpRequestMessage request, System.Net.HttpStatusCode statusCode, Exception exception);
static member CreateErrorResponse : System.Net.Http.HttpRequestMessage * System.Net.HttpStatusCode * Exception -> System.Net.Http.HttpResponseMessage
<Extension()>
Public Function CreateErrorResponse (request As HttpRequestMessage, statusCode As HttpStatusCode, exception As Exception) As HttpResponseMessage

Parameters

request
HttpRequestMessage

The request.

statusCode
HttpStatusCode

The status code of the created response.

exception
Exception

The exception.

Returns

HttpResponseMessage

An error response for exception with status code statusCode.

Remarks

This method requires that request has been associated with an instance of HttpContext.

Applies to

CreateErrorResponse(HttpRequestMessage, HttpStatusCode, String)

Helper method that performs content negotiation and creates a HttpResponseMessage representing an error with an instance of System.Net.Http.ObjectContent`1 wrapping an HttpError with message message. If no formatter is found, this method returns a response with status 406 NotAcceptable.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Net::Http::HttpResponseMessage ^ CreateErrorResponse(System::Net::Http::HttpRequestMessage ^ request, System::Net::HttpStatusCode statusCode, System::String ^ message);
public static System.Net.Http.HttpResponseMessage CreateErrorResponse (this System.Net.Http.HttpRequestMessage request, System.Net.HttpStatusCode statusCode, string message);
static member CreateErrorResponse : System.Net.Http.HttpRequestMessage * System.Net.HttpStatusCode * string -> System.Net.Http.HttpResponseMessage
<Extension()>
Public Function CreateErrorResponse (request As HttpRequestMessage, statusCode As HttpStatusCode, message As String) As HttpResponseMessage

Parameters

request
HttpRequestMessage

The request.

statusCode
HttpStatusCode

The status code of the created response.

message
String

The error message.

Returns

HttpResponseMessage

An error response with error message message and status code statusCode.

Remarks

This method requires that request has been associated with an instance of HttpContext.

Applies to

CreateErrorResponse(HttpRequestMessage, HttpStatusCode, HttpError)

Helper method that performs content negotiation and creates a HttpResponseMessage representing an error with an instance of System.Net.Http.ObjectContent`1 wrapping error as the content. If no formatter is found, this method returns a response with status 406 NotAcceptable.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Net::Http::HttpResponseMessage ^ CreateErrorResponse(System::Net::Http::HttpRequestMessage ^ request, System::Net::HttpStatusCode statusCode, System::Web::Http::HttpError ^ error);
public static System.Net.Http.HttpResponseMessage CreateErrorResponse (this System.Net.Http.HttpRequestMessage request, System.Net.HttpStatusCode statusCode, System.Web.Http.HttpError error);
static member CreateErrorResponse : System.Net.Http.HttpRequestMessage * System.Net.HttpStatusCode * System.Web.Http.HttpError -> System.Net.Http.HttpResponseMessage
<Extension()>
Public Function CreateErrorResponse (request As HttpRequestMessage, statusCode As HttpStatusCode, error As HttpError) As HttpResponseMessage

Parameters

request
HttpRequestMessage

The request.

statusCode
HttpStatusCode

The status code of the created response.

error
HttpError

The error to wrap.

Returns

HttpResponseMessage

An error response wrapping error with status code statusCode.

Remarks

This method requires that request has been associated with an instance of HttpContext.

Applies to

CreateErrorResponse(HttpRequestMessage, HttpStatusCode, String, Exception)

Helper method that performs content negotiation and creates a HttpResponseMessage representing an error with an instance of System.Net.Http.ObjectContent`1 wrapping an HttpError with error message message for exception exception. If no formatter is found, this method returns a response with status 406 NotAcceptable.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Net::Http::HttpResponseMessage ^ CreateErrorResponse(System::Net::Http::HttpRequestMessage ^ request, System::Net::HttpStatusCode statusCode, System::String ^ message, Exception ^ exception);
public static System.Net.Http.HttpResponseMessage CreateErrorResponse (this System.Net.Http.HttpRequestMessage request, System.Net.HttpStatusCode statusCode, string message, Exception exception);
static member CreateErrorResponse : System.Net.Http.HttpRequestMessage * System.Net.HttpStatusCode * string * Exception -> System.Net.Http.HttpResponseMessage
<Extension()>
Public Function CreateErrorResponse (request As HttpRequestMessage, statusCode As HttpStatusCode, message As String, exception As Exception) As HttpResponseMessage

Parameters

request
HttpRequestMessage

The request.

statusCode
HttpStatusCode

The status code of the created response.

message
String

The error message.

exception
Exception

The exception.

Returns

HttpResponseMessage

An error response for exception with error message message and status code statusCode.

Remarks

This method requires that request has been associated with an instance of HttpContext.

Applies to