Closed datvong-wm closed 4 years ago
It's an override. Whatever it returns will be the return value of the handler.
The example from the docs is wrong though. It just returns undefined
and performs some non-sensical async operation. As it is, H2o2 doesn't support any kind of async response handling. Maybe it should await
the result of the onResponse()
call?
So in this example, it should return Wreck.read()?
onResponse: function (err, res, request, h, settings, ttl) {
return Wreck.read(res, {json:true}, function(err, payload) {
return response;
});
}
I've just run into this too.
@hapi/wreck
now supports async/await, and h2o2 won't return a value if you use the callback syntax, even if you add return
onto the front of it. You need to use the async/await syntax.
just a doc update for the new wreck
, I'll do it once I've got my syntax working 100%.
According to the documentation:
It is not clear what onResponse should return. In this example, it doesn't return anything.