CopyPastor

Detecting plagiarism made easy.

Score: -1; Reported for: Open both answers

Possible Plagiarism

Reposted on 2018-01-14

Original Post

Original - Posted on 2018-01-14



            
Present in both answers; Present only in the new answer; Present only in the old answer;

This error may also come from the `UseDeveloperExceptionPage` middleware in a .NET Core API. This middleware strips all headers from the response which create CORS issues and causes the "TypeError: Failed to fetch" error you saw. Here is an example of my solution, which is described in full [here][1].
.NET Core Middleware --------------------
private static Task HandleExceptionAsync(HttpContext context, Exception exception) { var code = HttpStatusCode.InternalServerError;
var result = JsonConvert.SerializeObject(new { error = "An internal server error has occurred." }); context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)code; return context.Response.WriteAsync(result); }
Aurelia Interceptor -------------------
responseError(response: any): Promise<Response> { if (response instanceof Response) { return response.json().then((serverError: ServerError) => { // Do something with the error here. return Promise.reject<Response>(serverError.error); }); } }

[1]: https://blog.jonathaneckman.io/handling-net-core-web-api-exceptions-with-an-aurelia-fetch-interceptor/
The error parameter of `responseError` is any, so make sure it is what you think it is. In my case, I was expecting the failed response, but got back a caught `TypeError` exception. This is my interceptor:

responseError(response: any): Promise<Response> { if (response instanceof Response) { return response.json().then((serverError: ServerError) => { // Do something with the error here. return Promise.reject<Response>(serverError.error); }); } }
I also have had issues stemming from the way my exception handling middleware is configured in the .NET Core app. In my case, the `UseDeveloperExceptionPage` was causing CORS error in the fetch client. It doesn't sound like this is the same problem as yours, but you can compare your configuration to mine [here][1].

[1]: https://blog.jonathaneckman.io/handling-net-core-web-api-exceptions-with-an-aurelia-fetch-interceptor/

        
Present in both answers; Present only in the new answer; Present only in the old answer;