hapi icon indicating copy to clipboard operation
hapi copied to clipboard

Uncaught async errors in pre-handlers

Open jeff3yan opened this issue 9 years ago • 3 comments

I've noticed that uncaught errors from async handlers are now handled by the framework, courtesy of #3486.

Will a similar behavior also be applied onto pre handlers? Anything that executes in the pre phase seems to have the same input arguments and design conventions, so I was curious if this was an issue.

For example:

{
	method: 'GET',
	path: '/Items',
	config: {
		pre: [{
			assign: 'test',
			method: async function(request, reply) {
				throw new Error();
			}
		}]
	}
}

jeff3yan avatar Jul 13 '17 20:07 jeff3yan

It applies to other extension points (onRequest, onPreHandler, etc.) where this could also be very handy.

rubennorte avatar Aug 24 '17 13:08 rubennorte

@jeff3yan this ~will no longer be~ is no longer an issue in Hapi 17 (now in beta), as it'll remove all callback-style APIs and adopt Promises for all async methods.

rubennorte avatar Sep 29 '17 16:09 rubennorte

I am not going to add any new support for async/await/Promises in hapi v16. You will need to wait for v17 for proper and consistent handling of them.

hueniverse avatar Sep 29 '17 19:09 hueniverse