Migrate error handling code to NSError category