#pragma once // Spec: models.md "API error JSON shape and message selection". // { "error": , "messages": [string]? } // object error: detail.message ?? detail.errors.first ?? messages.first ; string error: messages.first ?? text. // Specific message -> isSpecific=true, else the generic text with isSpecific=false. // A non-2xx body that does not decode gives Kind::Http (generic text); 401 gives Kind::Unauthorized. #include #include #include "core/Result.hpp" namespace dp { class ApiErrorDecoder { public: struct Decoded { std::string message; bool isSpecific = false; }; // nullopt when the body is not a usable API error (no `error` key, wrong types, not JSON). static std::optional decodeBody(const std::string& body); static Error fromResponse(int status, const std::string& body); }; } // namespace dp