Closed ghost closed 8 years ago
It's a bit odd that you're getting 500 errors. Yar will not normally 500 error just because a key is missing. It'll return undefined. For the cache implementation we rely on Hapi to do all the communication. Yar doesn't directly connect to redis. It just asks Hapi to retrieve data from the cache, and Hapi does the redis work. If I had to guess I'd say you may have a misconfiguration issue, or a connectivity issue. I was able to get a 500 error when I configured a test hapi project with a redis caching backend, and then killed the redis server. That seems to support a connectivity issue.
If you have flaky redis connections going on then you'll have to wrap your yar.get calls with an error trapping mechanism, such as try/catch.
Hi,
I wanted to know what's the best way to handle yar.get errors, here's my code:
const indexHandler = (request, reply) => {
var userStatus = request.yar.get('authenticated').key; reply.view('./pages/index', { title: "Home", isAuthenticated: userStatus }) }
The first requests it throws a 500 error since it cannot get the key/value from redis, do I have to do a try catch and set value of userStatus to false only the first time, or is there a specific way to handle those errors with yar?
Thanks.