Refactor error handling to common