github polterguy/magic v9.7.1
Exception filters and interceptors

latest releases: v17.3.9, v17.3.8, v17.3.7...
2 years ago

The two major features in this release is the ability to create custom exceptions handlers that will kick in if you have an unhandled exception in your code, allowing you to transform exceptions to some sort of custom result, that is returned back to the client somehow, and/or apply additional logic as an unhandled exception occurs.

In addition you can create interceptors that makes it very easy to create "super DYR" code in Hyperlambda, where all commonalities for all files in some specific folder is implemented once and once only, in a file called "interceptor.hl" on a per folder basis.

Both of these features works similarly, in that you declare a file called ...

  • exceptions.hl - Custom exception handler Hyperlambda file
  • interceptor.hl - Interceptor Hyperlambda file

... in some folder of yours, where if an unhandled exception occurs, your exception handler file will be invoked with the parameters of the exception, and whatever you return from your handler is returned to the client.

For the interceptor, it works as follows ...

interceptor.hl file in some folder

log.info:Interceptor
.lambda

At which point what will happen is that all occurrences of any [.lambda] nodes in your "interceptor.hl" file will be replaced with the content of your actual endpoint file, allowing you to create much more dry code, where you don't repeat yourself, since you can put any common code into your interceptor file.

Don't miss a new magic release

NewReleases is sending notifications on new releases.