OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::anonymous_namespace{PrintHost.cpp} Namespace Reference

Functions

std::string moonraker_error_reason (const std::string &body)

Function Documentation

◆ moonraker_error_reason()

std::string Slic3r::anonymous_namespace{PrintHost.cpp}::moonraker_error_reason ( const std::string & body)
138{
139 const auto root = nlohmann::json::parse(body, nullptr, false);
140 const auto err = root.find("error");
141 if (err == root.end())
142 return {};
143 const auto message = err->find("message");
144 const auto traceback = err->find("traceback");
145 if (message == err->end() || traceback == err->end() || !message->is_string() || !traceback->is_string())
146 return {};
147
148 const auto &msg = message->get_ref<const std::string &>();
149 const auto &tb = traceback->get_ref<const std::string &>();
150 if (msg.empty())
151 return {};
152 const auto end = tb.find_last_not_of(" \t\r\n");
153 if (end == std::string::npos)
154 return msg;
155
156 // Chained exceptions each start a new traceback; the one that failed the request is the last.
157 const auto header = tb.rfind("Traceback (most recent call last):", end);
158
159 // Tornado renders a raised HTTPError as "HTTP <code>: <reason>[ (<detail>)]", and the detail may span lines.
160 const auto code = err->find("code");
161 if (code != err->end() && code->is_number_integer()) {
162 const std::string marker = "HTTP " + std::to_string(code->get<int>()) + ": ";
163 const auto pos = tb.rfind(marker, end);
164 if (pos != std::string::npos && (header == std::string::npos || pos > header) && pos + marker.size() <= end) {
165 const std::string reason = tb.substr(pos + marker.size(), end + 1 - pos - marker.size());
166 // An HTTPError whose detail equals its reason, like HTTPError(401, "Unauthorized"), renders the phrase twice.
167 return reason == msg + " (" + msg + ")" ? msg : reason;
168 }
169 }
170
171 // Any other exception's type and message are everything from the first unindented line after its frames.
172 auto begin = (header == std::string::npos) ? std::string::npos : tb.find('\n', header);
173 while (begin != std::string::npos && begin < end) {
174 ++begin;
175 if (tb[begin] != ' ' && tb[begin] != '\r' && tb[begin] != '\n')
176 break;
177 begin = tb.find('\n', begin);
178 }
179 if (begin == std::string::npos || begin > end) {
180 const auto nl = tb.rfind('\n', end);
181 begin = (nl == std::string::npos) ? 0 : nl + 1;
182 }
183 return msg + " (" + tb.substr(begin, end + 1 - begin) + ")";
184}
T * begin(Slic3r::Mat< N, M, T > &mat)
Definition Point.hpp:838
T * end(Slic3r::Mat< N, M, T > &mat)
Definition Point.hpp:841
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16
RaycastManager::TrItems::iterator find(RaycastManager::TrItems &items, const RaycastManager::TrKey &key)
Definition RaycastManager.cpp:298

References moonraker_error_reason().

Referenced by moonraker_error_reason().

Here is the call graph for this function:
Here is the caller graph for this function: