better error handling for cross origin resources