api: improve error messages for communication failure with Gandalf

Closes #296.