Cannot convert type Nancy.ErrorHandling.DefaultStatusCodeHandler.DefaultStatusCodeHandlerResult to Nancy.Response - exception

has anyone seen such exception before?
Cannot convert type
Nancy.ErrorHandling.DefaultStatusCodeHandler.DefaultStatusCodeHandlerResult
to Nancy.Response
I'm using nancy.owin with old asp.net mvc site.
this error happens when I'm configuring OWIN middleware using app.Map(path...) method
if I apply nancy middleware directly to the app (IAppBuilder) everything works as expected
but when I use app.Map(path) I get such exception. BUT: as a result in my postman I get 404 The resource you have requested cannot be found.

Related

How is the WeatherForecastController in template Blazor application configured to return JSON?

I created a standard Blazor Client application, but found when adding any new API controllers they simply do not work.
Even just copying the WeatherForecastController to a WeatherForecast2Controller returns the same error (as an HTML error page is returned instead of any JSON data):
'<' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
I assume there must be some configuration somewhere to tell it what return type to expect, but no idea where to look. The only controller that returns valid JSON data is the WeatherForecastController you get out of the box.
Works:
group = await Http.GetFromJsonAsync<GenericGroup[]>($"WeatherForecast");
Fails:
group = await Http.GetFromJsonAsync<GenericGroup[]>($"WeatherForecast2");
Controllers are identical aside from name (literally copied the existing controller). I have been through every single file in the solution and don't see anything that would cause WeatherForecast to be a special routing.
Clue 1:
It does not hit a breakpoint in any controller aside from the WeatherForecastController
Clue 2:
The HTML returned (which causes the Json deserialise to fail) is actually the initial Loading... from the Blazor client load, so it looks like the requests are going to the standard routing and not treated as API calls.
Clue 3:
This does not happen unless authentication has been added to the application. I tried it on a vanilla Blazor app (no auth) and it works just fine. The failing app is using Azure B2C for auth.
Turns out you can cause things to blow up if you inject the wrong logger parameter in the generic ILogger<>. It was the one thing I missed changing. Good to know.

VM892:1 Uncaught SyntaxError: Unexpected token e in JSON at position 0

I'm presently working on a phx / phoenix API written in Elixir. And I have created a frontend for the API using React.js. However, I'm getting the below error message in the JS console of the browser.
I have successfully created a user using Postman, so I'm 99% sure the error isn't with the phx project, but rather somewhere with the React project.
I have both the frontend and backend hosted on github. And a .env file will need to be created in the root of the React project with the below line,
REACT_APP_API_URL=http://localhost:4000/api
and was working my way through the following tutorial.
Any and all help would greatly be appreciated.
The output of localStorage.getItem("token") being
eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJVc2VyOjEiLC‌​JleHAiOjE0ODcyODI4OD‌​csImlhdCI6MTQ4NDY5MD‌​g4NywiaXNzIjoiUGhvZW‌​5peENoYXQiLCJqdGkiOi‌​IwNzFlYzgwYi0wZmYzLT‌​QyYzgtODA3Mi1kNzViZm‌​VhZTg4NWEiLCJwZW0iOn‌​t9LCJzdWIiOiJVc2VyOj‌​EiLCJ0eXAiOiJhY2Nlc3‌​MifQ.NsuqH50HooK8vjF‌​fHtPH9iXSykZ9oYA0ul4‌​b_C5fQtpu_zFvNNy-skc‌​v9HI2i25X-NlB-9xOr-x‌​zh2abnrpYUw
suggests that for some reason, the app stored the token without passing it through JSON.stringify, and calling JSON.parse on this string throws the Unexpected token e error, as expected.
I did not see any localStorage.setItem without JSON.stringify in the current code, so the token was probably stored like that in a previous version of the app. You should try clearing it manually and logging in again.
When we get the non-JSON response, we get such error..
To avoid such error, mention the responseType: Text in your api endpoint call.
This will work,
return this.http.post(`${environment.apiUrl}/login`, user, {responseType: 'text'});
This will not work(If you mention type),
return this.http.post<string>(`${environment.apiUrl}/login`, user, {responseType: 'text'});
This error message usually means you're getting a non-JSON response. If you look at the raw response in the Network tab of your debugger, you should be able to see what you're getting back from the server.

Debugging Web Service that fails as JSON but not as XML

I have a webservice method that if I call directly via url GET returns XML without issue.
However, POST to that same url with Content-Type Json, it fails.
I think I can figure out the issue (I'm guessing it's an encoding or bad character somewhere in there) but I don't know how to debug the problem.
If I set a breakpoint in the webservice, it runs to completion. The failure appears to be happening AFTER the method returns, but BEFORE the json is returned to the caller.
How can I get in between to trace the error?
Please let me know if I can provide more context to help, but I really just need to know how to get in there.
EDIT:
The web service is configured to receive POST and return JSON and in fact DOES correctly return JSON in some cases. However, there are certain calls that are failing, so I need a way to trace this or debug it somehow and figure out why some calls are not working.
The web service is likely not configured to receive POST requests, especially if you are receiving a 405 Method Not Allowed response status.
Although I didn't find a way to debug or intercept the request to find the exact answer, it turns out the problem was the size of the content being returned by the webservice. Following this answer: ASP.NET WebMethod with jQuery json, is there a size limit?
and increasing the json limit fixed the issue!
Is there a way I could have trapped this to find the error without just guessing it was a size limit?

symfony2 exceptions - don't return HTML

I've got a symfony2 bundle where I use jquery terminal project. It's a simple javascript console where the user passes some instructions which are executed on server side with AJAX/JSON and returned to the console and displayed. The php server scripts reads the browser-terminal request from $GLOBALS['HTTP_RAW_POST_DATA'].
Currently, when any request throws an error, symfony2 returns a whole HTML response. I don't want the HTML part (I'd like to display the exception message/code only).
The problem is: symfony2 handles exceptions and catches them somewhere, embedding in HTML and returns such response. I want to modify this - the exc. may be caught, but I want no HTML included. There is one distinct bundle, made only for the console stuff.
In fact, the problem was that there was exit statement missing in the controller. The controller response was empty, so an exception was thrown, that a controller has to return a response. After adding exit; after echoing the output, the problem was gone.

In Spring 3.0.5 and coding it to serve JSON, what is this log output trying to tell me?

Using Spring 3.0.5, I am trying to return a list of strings in JSON format.
I read the post spring-mvc-json-response
I have available to me jackson-mapper code 1.4.2 and it's on my classpath.
I am also using <context:component-scan base-package="com.funfun.foofoo2" /> which should satisfy the <mvc:annotation-driven> requirement.
I am returning a List<String> although I have tried just a bean too.
When I return raw JSON as a String, it works.
What is the following log output telling me? Is it saying it cannot find the Jackson JSON Mapper and thus the MappingJacksonHttpMessageConverter is not loaded?
17:19:01,037 DEBUG [AnnotationMethodHandlerExceptionResolver:132] Resolving exception from handler [com.funfun.foofoo2.CarModelsController#181fa4b]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
17:19:01,037 DEBUG [ResponseStatusExceptionResolver:132] Resolving exception from handler [com.funfun.foofoo2.CarModelsController#181fa4b]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
17:19:01,037 DEBUG [DefaultHandlerExceptionResolver:132] Resolving exception from handler [com.funfun.foofoo2.CarModelsController#181fa4b]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
17:19:01,053 DEBUG [DispatcherServlet:824] Null ModelAndView returned to DispatcherServlet with name 'appServlet': assuming HandlerAdapter completed request handling
Update: I am using jQuery's getJSON. In Firefox Firebug, I see the header coming over as application/json. The Spring method is constrained to only handle requests for JSON.
You need more than jackson-mapper, you need jackson-core as well, and preferably something newer than the rather old 1.4.x versions.
Basically what this exception (HttpMediaTypeNotAcceptableException) means is that the client is specifying an accepts header in their HTTP request, and it likely isn't accepting JSON. How are you making this request? AJAX call? If so, use Firebug or something to inspect the XHR and see what the accepts header is set to.
Just check the Accept param in your HTTP request header. If you are using XMLHttpRequest to make the ajax call, don't forget to change the requestHeader as follow:
xmlhttp.open("POST", custom_url, this.async);
xmlhttp.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml,application/json;q=0.9,*/*;q=0.8");
Regards,
David.