Allow the error thrown on failure to be customized.