0

I want to have a catch for errors and success for the server.inject method as currently if it throws an error, it is not caught by the function doing the inject, so how would I do that with a function like this

I am using hapi (17.x)

server.inject({
  method: 'POST',
  url: `/xxx`,
  payload: {
    x: x
  }
});
dhj
  • 4,780
  • 5
  • 20
  • 41

1 Answers1

1

in hapi 17 you need to use async await. with that, you can use try/catch.

try {
  await server.inject(options)
} catch(e) {
  //handle error here
}
nxmohamad
  • 1,731
  • 2
  • 19
  • 31