Skip to content
Repos

DevPlaceApp

C++ 1.0 KB28 lines Opens in site

Directory Raw Download

#include "core/AlertMessage.hpp"

#include "core/Log.hpp"
#include "spec/UiMessages.hpp"

namespace dp {

AlertMessage AlertMessage::none() { return AlertMessage{}; }

AlertMessage AlertMessage::presentedError(const std::string& message) {
  return AlertMessage{true, spec::UiMessages::kAlertErrorTitle, message, spec::UiMessages::kAlertButton};
}

AlertMessage AlertMessage::presentedMessage(const std::string& message) {
  return AlertMessage{true, "", message, spec::UiMessages::kAlertButton};
}

AlertMessage AlertMessage::presentedError(const Error& error) {
  if (error.kind == Error::Kind::Cancelled) return none();
  std::string text = error.message;
  const bool apiClass = error.kind == Error::Kind::Api || error.kind == Error::Kind::Unauthorized ||
                        error.kind == Error::Kind::Http;
  if (apiClass && error.status > 0 && !error.isSpecific) text = "(" + std::to_string(error.status) + ") " + text;
  Log::debug("Error: " + error.message);
  return presentedError(text);
}

}  // namespace dp
28.9ms