Properly handle panics in the handler