Troubleshooting 500 Server Errors from POST requests

So, I am building an Ionic 3 app along with an API in ASP.NET Core MVC. The entire app functions as expected in Chrome using ionic serve with the API running in debug mode alongside. I used a proxy in the ionic config file to get around the origin issue, and all works great in that environment. I deployed the API to a live server and all the GET requests function fine in a browser, but I’m getting 500 errors back from the POST requests when I run cordova run android on a device. Again, they all function fine in the development environment running ionic serve for the app, and Visual Studio to debug the API.

I’m at home now and don’t have direct access to the code, but I’m hoping I can get some ideas for how to move forward with troubleshooting tomorrow, because all I seem to get back from the post requests on my device is 500 - Server Error.

There’s nothing you can tell from the client side, you’ll need to check your server logs

1 Like

Okay, so what is the best source for that info? I spent much of the afternoon trying to troubleshoot, and nothing was showing up on the Event Viewer on the server. I also have my ASP Core web api configured to log errors through stdout, but nothing comes out. I was able to see errors earlier as I was migrating the api over and dealing with changing the environment over to .NET Core, but once the get requests started showing up in a browser, the errors stopped showing up in the logs I was looking at. Any other tools you know of I could use to get at what’s going on?

Without knowing about your specific server setup I can’t really tell you. I come from a mostly PHP background - so when I encounter a 500 error on a PHP endpoint I can always watch the logs while I trigger it and get some relevant information.

eg.
tail -f /var/log/httpd/error.log

While ssh’d into the server, trigger the post action, see what the error says. If it’s not logging for some reason then that’s a config issue with your server.

First off, thanks for the replies. I’m sure this may seem like either I’m a newbie altogether, or this topic is simply not related to Ionic, both good reasons to ignore me.

Anyway, I have been able to get beyond 500 errors to a 415 - unsupported media type error. This would seem to be an issue with the object I’m sending in the post body. Just to recap:

I have an API built in visual studio. I can run it in debugging mode at localhost:someport.

I have an ionic app built in a separate IDE. I have a proxy set to get around CORS in ionic.config.json. I can run the app in the browser using ionic serve, and all my requests work perfectly. The app is built and all seems fine in browser.

I deploy the API to my server, and all GET requests come back to my browser fine, so I know the API is functioning, but when I go to test the app on my device or even from a service like hurl.it the server returns 415, unsupported media type.

I am getting the post request body this way:

let reqBody = [];
      let criteria = this.searchCriteriaForm.value;
      for (var k in criteria) {
        if (criteria.hasOwnProperty(k)) {
          reqBody.push({
            'searchField' : k,
            'searchTerm' : criteria[k]
          });
        }
      }
      console.log(reqBody);
      this.navCtrl.push('SearchResultsPage', {
        'criteria' : reqBody
      });

The SearchResultsPage is making the request this way:

this.http.post(url, queryObj).map(res => res.json()).subscribe(data =>
{ this.stuff = data; });

This all works fine localhost to localhost, but when I make the request to the live IIS server I get the unsupported media type issue. My assumption here is that I have something configured wrong with the API, but it’s strange to me that it would handle the request fine in development and not on the server itself.

Any advice would be appreciated.

So, I’ll go ahead and update the situation here. This was definitely an issue with the ASP.NET API, and nothing to do with Ionic or Angular. Sorry to waste space here, but if anybody else runs into something like this, where you’re getting 500 errors back from AJAX calls to IIS, you can add a /logs folder to your API, and set the stdoutLogEnabled flag to true in your web.config file for the API. It would look like this:

<configuration>
  <system.webServer>
    <aspNetCore processPath="dotnet" arguments="myApp.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>

Do note that you will need to manually create the \logs\ folder in the root of your API for logging to work. My issue turned out to be an integrated security issue logging into the database. Easy fix after 3 days troubleshooting. Error logs are critical!

Anyway, thanks for the input.