ejs
ejs copied to clipboard
Trapping an ejs render error
My application using express, crashes with the ejs render error data like it should. However I need to trap the error and handle it gracefully as I move into production. Now, the app crashes in the docker image, but kubernetes thinks it is still alive. I would like to show the user a "ooops" error page, instead of the render error and crash. I have posted in Stackoverflow but no response. I am looking on how to get kubernetes to see that it has crashed and restart.
Thanks Brad
Brad, why don't you try ensuring all the data to be render ejs are present using a wrapper /validation function to check if none of the object property are null || undefined , if the condition is true the render the page but if not create a custom route to render the error page .
function validateRenderObject(data){
for(let prop in data){
if(typeof prop == undefined || typeof prop==null){
return false;
}
return true;
}
}
app.get('/index',(req,res,next)=>{
if(validateRenderObject(data)){
res.render('page',data)
}else{
res.redirect(500,'/error')
}
})
app.get('/error',(req,res,next)=>{
res.render('error',obj);
})
Leave a comment
No action to take here, closing the issue.