stateful-result – nodejs module for represent operation result with status code

Nodejs stateful-result module

This module can be used for representing an operation(e.g: function return) result with a meaningful status code. By default, we suggest to make use of HTTP status code. Hence, code 200 for status of operation OK, and code 404 for status of operation target not found, etc.




Sample 1: Getting success result (code 200 OK)

console output


Simple enough, isn’t it?

Sample 2: Getting fail result (code 404 Not found)

console output

Description: The error object is an extended error object which has the “code” attribute. In this case, the code is 404.

Sample 3: Get result if success result or throw error if returning fail result (code 404 Not found)

console output

Description: This time we called method “getOrThrow”. If the result is success, the result would be returned as previous samples. If the result is fail, the error object would be thrown.

Leave a Reply

Your email address will not be published.