I Multiply Happiness by Sharing!

Yeah, it’s me again with Node.js and PowerShell but this time for exception handling series of blogs and this is part 1 – Handling Exceptions are must in development practice right? But, how we output to end users matters a lot. For example consider the below error

Cannot GET /hello

There is no such route (hello) exists and it’s clear for developers. Let us add few piece of code to show friendly error message with email link to report the issue when end user lands in non existing endpoints or in application.

so ultimately our first result will be like
All good! No, still we need to work bit more on code. Before the JS let us see how we can play with PowerShell exceptions. Yes, for this I used node-powershell package and don’t worry child_process works the same way! For a demo, the script file I created is Exception1.ps1 under scripts folder and code is as shown below

Ahhhhhhh! A phone rings saying “Hey Chen I don’t know Chinese! Can you read and make it clear for me?”

That’s bad right? As a first step If we correct the file name we are out of funkiness but again the exception we catch in PS throws “Attempted to divide by zero“. So, we need to render a pug file with more information.

With minimum effort we can give more information to L1 support engineers and end users will not panic looking into the issue. In my next blog post we will continue to explore more about exception handling!