Adding exception handling for invalid requests.