helics  3.5.2
JsonGeneration.hpp
1 /*
2 Copyright (c) 2017-2024,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 #pragma once
8 
9 #include "json/json.h"
10 #include "json/writer.h"
11 #include <fmt/format.h>
12 #include <string>
13 
14 namespace helics {
15 
16 inline std::string generateJsonQuotedString(const std::string& string)
17 {
18  Json::String V = Json::valueToQuotedString(string.c_str());
19  return V.c_str();
20 }
21 
22 enum class JsonErrorCodes : std::int32_t {
23  BAD_REQUEST = 400,
24  FORBIDDEN = 403,
25  NOT_FOUND = 404,
26  METHOD_NOT_ALLOWED = 405,
27  TIMEOUT = 408,
28  DISCONNECTED = 410,
29  INTERNAL_ERROR = 500,
30  NOT_IMPLEMENTED = 501,
31  BAD_GATEWAY = 502,
32  SERVICE_UNAVAILABLE = 503,
33  GATEWAY_TIMEOUT = 504
34 };
36 inline std::string generateJsonErrorResponse(JsonErrorCodes code, const std::string& message)
37 {
38  return fmt::format("{{\n \"error\":{{\n \"code\":{},\n \"message\":{}\n }}\n}}",
39  static_cast<std::int32_t>(code),
40  generateJsonQuotedString(message));
41 }
42 
43 } // namespace helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
std::string generateJsonErrorResponse(JsonErrorCodes code, const std::string &message)
Definition: JsonGeneration.hpp:36