report error whenever an error occur in project - node.js

My requirement is to send the error to developers whenever an error occurs in the project (ex: unable to fetch the user from the database, var x is not defined, myfun() is not a function etc.)
We are using
NODE for backend language
Express for routing
GCP for deployment
PM2 package for management
Express default error handling is not working because we have many async codes, and it's very difficult to check and modify the project using express next() function.
I didn't find any way to report project error via GCP
and report error via pm2 is not working
Please tell me any third party package to report project errors or any other way of reporting.

User Stackdriver as already advised, and for Stackdriver to be useful, make sure that all errors are logged properly in your code, so that meaningful error messages are displayed in your Stackdriver reports.
Check this post for different methods of catching errors with Javascript, and how to deal with asynchronous calls.

Related

Vue alert message handling

I love the vue.js impl.. so easy and fast to develop with but it appears that the error handling for api errors is not working (not the same as with react.js anyway).
E.g. if I try to save an entity with a field value that is supposed to be unique (but is not) then the page does not display any error alert at all. I do see one in the js console, but it looks like its not handled in the ui code.
Is there something more I need to do ?

Determine route that causes PayloadTooLargeError

We have a NodeJS app that uses Express. We've seen a few PayloadTooLargeError message start to pop up, but the problem is we don't know whats causing it or how to recreate. The error message also doesn't give us any indication of which route the error is occurring on. Is there a way for the stack trace or error message to detail which route is causing the error? We have quite a few routes with APIs from multiple services, so debugging them all is almost impossible.
Adding a custom middleware that logs the request uri before the route is called will allow you to see which uris are throwing errors.

How to get swaggerize-express to ouput input validation information

I'm setting my Node.js project with swaggerize-express, and are currently testing my backen using supertest to test my backend.
When I run the supertests, and it fails due to swagger rejecting (i.s. input validation fails) the data I pass to it, currently I simply get a 400 error message, without any details on what's wrong with my query.
I'd like the backend to provide some hints as to what input data it rejects. I haven't found any debug options to set in swaggerize-express, so how can I go about getting the backend to ouput some details on the validation errors? Wether the validation errors are provided in the server log or in the data returned to the client is not important at this point, although I'd prefer the latter.
if you deploy your API in a Microsoft Azure App Service you will take benefit of the Output Logs.
Check my post on how to deploy a node.js API quickly in Azure:
http://mosshowto.blogspot.fr/2017/10/try-azure-app-service.html
When it's deployed, go to the Visual Studio Code online editor, check your deployment.Then, Hit the run button. The server will try to start your API and will log any error in the output if needed:

WebApi application on Azure returning 500 errors for some endpoints

I am setting up an ASP.NET WebApi application running on the Azure web application environment. Most of my controllers and endpoints work fine, but there are about 10 routes that return 500 errors "An error has occured". It's not random. It's the same routes every time and I can find no pattern (not all the HTTP methods, from different controllers where other routes in that same controller work fine, and so forth)
When these errors occur, no error logging gets triggered as far as I can tell in the app. (I am using Raygun.IO if that matters). I tried adding a global.asax file with following lines in the Application_Error function:
Exception ex = Server.GetLastError();
new RaygunClient().SendInBackground(null, ex);
but as far as I can see, it doesn't get triggered when these 500 errors occur. The only thing I have found in the Azure server logs is the following warning in the Failed Requests log:
However, I don't see any errors in the trace previous to that point. I'm also not finding any other errors in any of my Azure logs that I can relate to these failing routes.
It's .NET 4.6 (tried 4.5.1 and 4.5.2 with no difference) WebApi using an OWIN startup class. Also tried updating all my packages to no effect.
Check to be sure you don't have routes that conflict. When a URI matches two or more controller actions, and thus Web API can't pick one, you will get a 500 error.
If you have a consistent repro, then you can use remote debugging to attach to your web app and debug it (https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-troubleshoot-visual-studio/). If you can repro it through the browser, you can also turn the custom errors page off so that it shows the stack trace through the browser (<customErrors mode="off"/> under <server.web>).
Also, you can enable better diagnostic logs using the web app settings. Information on how to do so is here: https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/ under the section "Enabling diagnostic logs".
Also, as Brent said, URL conflicts can cause some nasty errors which aren't immediately obvious.
I figured out what was going on. There were actual errors occurring (mostly SQL related), but the way that we had configured the functions and error logging in those functions, the actual errors were being swallowed up and lost, overriding the error logging behavior of Raygun. I went through and ripped out the Try/Catch blocks we were using for error trapping and logging and the real errors finally emerged into the Raygun dashboard.

How to proper log every exception using OWIN

my question should be quite simple, but unfortunately I had no luck in solving it.
Basically, I have some Web API controllers hosted by OWIN and deployed on Azure.
I really need to track down exceptions that occur in each middleware (for example OAuthAuthorizationServerProvider or SignalR Persistent Connections), but I definitely don't have a clue on how to achieve it.
I tried Elmah, but it doesn't seem to work properly with OWIN due to lacking HttpContext.
I tried using log4net, but I'm only able to log exceptions thrown by Web API Controllers using a custom ExceptionFilterAttribute.. others are ignored.
I tried to define a custom LoggerFactory and to assign it in Startup, using app.SetLoggerFactory(new MyLoggerFactory()),
but exception thrown by other middlewares are not logged.
I tried to get at least a meaningful error message sent to the client, but despite <customErrors mode="Off"/> and <deployment retail="false"/>, Azure refuses to return anything but {"message":"an error has occurred"}.. I tried both Azure Web Sites and Azure Cloud Services.
I saw some cloud alternatives that should work with OWIN, like Elmah.io or Raygun.io, but I don't need their cloud features and it is definitely not worth paying hundreds $ per year just to log some exceptions.
What should be the best way to log any possible exception thrown by my application?
Thanks for your help
have you take a look at this link ? http://www.asp.net/web-api/overview/error-handling/web-api-global-error-handling
Because you can't catch all the exceptions using an exceptionFilter, they propose to use a IExceptionLogger and IExceptionHandler to allow global error handling in Web Api 2.
After that, if it's not fit your need, you can construct an OwinMiddleWare that you will place in first position (before the Authenticate stage), this middleware could :
create a requestId in the header of the response
analyse the response code, before sending response, and if it's not a IsSuccessStatusCode, you could log the exception message to a DB and replace the content of the response to send a simple error message to the client using the requestId (to allow you to find the related exception in your db)
hope this help

Resources