46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
#pragma once
|
|||
|
|
|
||
|
|
// One error type for every Google call. Carries the HTTP status, Google's
|
||
|
|
// own status string and a message; never the credential.
|
||
|
|
|
||
|
|
#include <stdexcept>
|
||
|
|
#include <string>
|
||
|
|
|
||
|
|
#include "clients/response.h"
|
||
|
|
|
||
|
|
namespace molo::google {
|
||
|
|
|
||
|
|
class GoogleError : public std::runtime_error {
|
||
|
|
public:
|
||
|
|
GoogleError(int http_status, std::string status, const std::string& message,
|
||
|
|
std::string service = "");
|
||
|
|
|
||
|
|
int http_status() const noexcept { return http_status_; }
|
||
|
|
const std::string& status() const noexcept { return status_; }
|
||
|
|
const std::string& service() const noexcept { return service_; }
|
||
|
|
// The message alone, without the "molo::google: STATUS:" prefix of what().
|
||
|
|
const std::string& message() const noexcept { return message_; }
|
||
|
|
|
||
|
|
// Validation failure raised before any network traffic.
|
||
|
|
static GoogleError invalid(const std::string& message);
|
||
|
|
|
||
|
|
private:
|
||
|
|
int http_status_;
|
||
|
|
std::string status_;
|
||
|
|
std::string service_;
|
||
|
|
std::string message_;
|
||
|
|
};
|
||
|
|
|
||
|
|
// Raised when no credential is configured. HTTP 503, status NOT_CONFIGURED.
|
||
|
|
class NotConfiguredError : public GoogleError {
|
||
|
|
public:
|
||
|
|
explicit NotConfiguredError(const std::string& service);
|
||
|
|
};
|
||
|
|
|
||
|
|
// Maps a non-2xx response (Google's {"error":{code,message,status}} body, or
|
||
|
|
// anything else) to a GoogleError.
|
||
|
|
GoogleError error_from_response(const std::string& service,
|
||
|
|
const clients::ClientResponse& response);
|
||
|
|
|
||
|
|
} // namespace molo::google
|