Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

ChromelyResponse.Status is ignored #110

Closed
Rodriguevb opened this issue Jul 22, 2019 · 1 comment
Closed

ChromelyResponse.Status is ignored #110

Rodriguevb opened this issue Jul 22, 2019 · 1 comment

Comments

@Rodriguevb
Copy link

I would like to return a code http 404 with ChromelyResponse. But it is ignored and replaced by a 200 code.

jquery:

$.ajax({
	url: myLocalUrlToCsharp,
	type: 'POST',
	dataType: "json",
	accepts: "application/json; charset=utf-8",
	data: JSON.stringify(data),
	complete: function (output) {

		// output is always:
		// {
		//	readyState: 4,
		//	responseText: "{\"Data\":\"No Data\"}",
		//	responseJSON : {"Data":"No Data"},
		//	status: 200,
		//	statusText: "Ok"
		//}
	}
});

C#

private static ChromelyResponse Connect(ChromelyRequest request)
{
	return new ChromelyResponse(request.Id)
	{
		Status = 404,
		StatusText = "Not Found",
		Data = "No Data"
	}
}

Can anyone explain my mistake? Thanks

@mattkol
Copy link
Member

mattkol commented Jul 23, 2019

@Rodriguevb the status is set based on the success (or failure) of a request processing. It was not designed to be part of response data itself. If you want a status as part of the "content" then it will be part of the data, using the "Data" property.

private static ChromelyResponse Connect(ChromelyRequest request)
{
       var content = new SomeClass() {
	       Status = 404,
		StatusText = "Not Found",
		Data = "No Data"
       }
	return new ChromelyResponse(request.Id)
	{
		Data = content
	}
}

The alternative is to create a custom HTTP Scheme handler to override default behavior. Please see..Register New Scheme

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants