api/server: better error checking to avoid unnecessary panics

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
Merge pull request #5537 from shykes/pr_out_api_server_better_error_checking_to_avoid_unnecessary_panics