flatten error handling