try-catch-logger
v0.0.1
Published
A utility package for your repetitive try catch with a proper standard logging format with both async and normal function compatible.
Downloads
3
Maintainers
Readme
try-catch-logger
A utility package for handling repetitive try-catch blocks, compatible with both asynchronous and synchronous functions, featuring standard logging formats.
Authors
Usage/Examples
It is compatible with both asynchronous and synchronous functions you dont have to provide any specific properties. It automatically identifies the type of the function.
How to use
- Pass the function as 0 th argument
- Pass rest of the arguments to the respective function
What will be returned
- status - Function Execution Status -> true, false
- data - Anything returned from the function
- error - Error occured in the function
Arguments
// Arguments order is mainter same as what you pass to main function
tryCatchLogger(anyFunction, param1, param2);
sync example
const tryCatchLogger = require('try-catch-logger');
async function sampleSyncFunc (param1){
console.log("hello", param1);
return sampleSync
}
function mainFunc(){
let {status, data, error} = tryCatchLogger(sampleSyncFunc, 2)
console.log(status) // Function Execution Status -> true, false
console.log(data) // Anything returned from the function
console.log(error) // Error occured in the function
}
async example
const tryCatchLogger = require('try-catch-logger');
async function sampleAsyncFunc (param1){
let sampleAsync = await fetch('https://jsonplaceholder.typicode.com/todos/'+ 'param1')
return sampleAsync
}
async function mainFunc(){
let {status, data, error} = await tryCatchLogger(sampleAsyncFunc, 2)
console.log(status) // Function Execution Status -> true, false
console.log(data) // Anything returned from the function provided
console.log(error) // Error occured in the function
}
mainFunc()
Feedback
If you have any feedback, please reach out to us at [email protected]
License
This is an open-source package with a MIT License.