1 /*
2 // Copyright (c) 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 #include "error_messages.hpp"
17 
18 #include "http_response.hpp"
19 #include "logging.hpp"
20 #include "registries.hpp"
21 #include "registries/base_message_registry.hpp"
22 
23 #include <boost/beast/http/field.hpp>
24 #include <boost/beast/http/status.hpp>
25 #include <boost/url/url_view_base.hpp>
26 #include <nlohmann/json.hpp>
27 
28 #include <array>
29 #include <cstddef>
30 #include <cstdint>
31 #include <source_location>
32 #include <span>
33 #include <string>
34 #include <string_view>
35 #include <utility>
36 
37 // IWYU pragma: no_include <stddef.h>
38 
39 namespace redfish
40 {
41 
42 namespace messages
43 {
44 
45 static void addMessageToErrorJson(nlohmann::json& target,
46                                   const nlohmann::json& message)
47 {
48     auto& error = target["error"];
49 
50     // If this is the first error message, fill in the information from the
51     // first error message to the top level struct
52     if (!error.is_object())
53     {
54         auto messageIdIterator = message.find("MessageId");
55         if (messageIdIterator == message.end())
56         {
57             BMCWEB_LOG_CRITICAL(
58                 "Attempt to add error message without MessageId");
59             return;
60         }
61 
62         auto messageFieldIterator = message.find("Message");
63         if (messageFieldIterator == message.end())
64         {
65             BMCWEB_LOG_CRITICAL("Attempt to add error message without Message");
66             return;
67         }
68         error["code"] = *messageIdIterator;
69         error["message"] = *messageFieldIterator;
70     }
71     else
72     {
73         // More than 1 error occurred, so the message has to be generic
74         error["code"] = std::string(messageVersionPrefix) + "GeneralError";
75         error["message"] = "A general error has occurred. See Resolution for "
76                            "information on how to resolve the error.";
77     }
78 
79     // This check could technically be done in the default construction
80     // branch above, but because we need the pointer to the extended info field
81     // anyway, it's more efficient to do it here.
82     auto& extendedInfo = error[messages::messageAnnotation];
83     if (!extendedInfo.is_array())
84     {
85         extendedInfo = nlohmann::json::array();
86     }
87 
88     extendedInfo.push_back(message);
89 }
90 
91 void moveErrorsToErrorJson(nlohmann::json& target, nlohmann::json& source)
92 {
93     if (!source.is_object())
94     {
95         return;
96     }
97     auto errorIt = source.find("error");
98     if (errorIt == source.end())
99     {
100         // caller puts error message in root
101         messages::addMessageToErrorJson(target, source);
102         source.clear();
103         return;
104     }
105     auto extendedInfoIt = errorIt->find(messages::messageAnnotation);
106     if (extendedInfoIt == errorIt->end())
107     {
108         return;
109     }
110     const nlohmann::json::array_t* extendedInfo =
111         (*extendedInfoIt).get_ptr<const nlohmann::json::array_t*>();
112     if (extendedInfo == nullptr)
113     {
114         source.erase(errorIt);
115         return;
116     }
117     for (const nlohmann::json& message : *extendedInfo)
118     {
119         addMessageToErrorJson(target, message);
120     }
121     source.erase(errorIt);
122 }
123 
124 static void addMessageToJsonRoot(nlohmann::json& target,
125                                  const nlohmann::json& message)
126 {
127     if (!target[messages::messageAnnotation].is_array())
128     {
129         // Force object to be an array
130         target[messages::messageAnnotation] = nlohmann::json::array();
131     }
132 
133     target[messages::messageAnnotation].push_back(message);
134 }
135 
136 static void addMessageToJson(nlohmann::json& target,
137                              const nlohmann::json& message,
138                              std::string_view fieldPath)
139 {
140     std::string extendedInfo(fieldPath);
141     extendedInfo += messages::messageAnnotation;
142 
143     nlohmann::json& field = target[extendedInfo];
144     if (!field.is_array())
145     {
146         // Force object to be an array
147         field = nlohmann::json::array();
148     }
149 
150     // Object exists and it is an array so we can just push in the message
151     field.push_back(message);
152 }
153 
154 static nlohmann::json getLog(redfish::registries::base::Index name,
155                              std::span<const std::string_view> args)
156 {
157     size_t index = static_cast<size_t>(name);
158     if (index >= redfish::registries::base::registry.size())
159     {
160         return {};
161     }
162     return getLogFromRegistry(redfish::registries::base::header,
163                               redfish::registries::base::registry, index, args);
164 }
165 
166 /**
167  * @internal
168  * @brief Formats ResourceInUse message into JSON
169  *
170  * See header file for more information
171  * @endinternal
172  */
173 nlohmann::json resourceInUse()
174 {
175     return getLog(redfish::registries::base::Index::resourceInUse, {});
176 }
177 
178 void resourceInUse(crow::Response& res)
179 {
180     res.result(boost::beast::http::status::service_unavailable);
181     addMessageToErrorJson(res.jsonValue, resourceInUse());
182 }
183 
184 /**
185  * @internal
186  * @brief Formats MalformedJSON message into JSON
187  *
188  * See header file for more information
189  * @endinternal
190  */
191 nlohmann::json malformedJSON()
192 {
193     return getLog(redfish::registries::base::Index::malformedJSON, {});
194 }
195 
196 void malformedJSON(crow::Response& res)
197 {
198     res.result(boost::beast::http::status::bad_request);
199     addMessageToErrorJson(res.jsonValue, malformedJSON());
200 }
201 
202 /**
203  * @internal
204  * @brief Formats ResourceMissingAtURI message into JSON
205  *
206  * See header file for more information
207  * @endinternal
208  */
209 nlohmann::json resourceMissingAtURI(const boost::urls::url_view_base& arg1)
210 {
211     std::array<std::string_view, 1> args{arg1.buffer()};
212     return getLog(redfish::registries::base::Index::resourceMissingAtURI, args);
213 }
214 
215 void resourceMissingAtURI(crow::Response& res,
216                           const boost::urls::url_view_base& arg1)
217 {
218     res.result(boost::beast::http::status::bad_request);
219     addMessageToErrorJson(res.jsonValue, resourceMissingAtURI(arg1));
220 }
221 
222 /**
223  * @internal
224  * @brief Formats ActionParameterValueFormatError message into JSON
225  *
226  * See header file for more information
227  * @endinternal
228  */
229 nlohmann::json actionParameterValueFormatError(
230     const nlohmann::json& arg1, std::string_view arg2, std::string_view arg3)
231 {
232     std::string arg1Str =
233         arg1.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
234     return getLog(
235         redfish::registries::base::Index::actionParameterValueFormatError,
236         std::to_array<std::string_view>({arg1Str, arg2, arg3}));
237 }
238 
239 void actionParameterValueFormatError(
240     crow::Response& res, const nlohmann::json& arg1, std::string_view arg2,
241     std::string_view arg3)
242 {
243     res.result(boost::beast::http::status::bad_request);
244     addMessageToErrorJson(res.jsonValue,
245                           actionParameterValueFormatError(arg1, arg2, arg3));
246 }
247 
248 /**
249  * @internal
250  * @brief Formats ActionParameterValueNotInList message into JSON
251  *
252  * See header file for more information
253  * @endinternal
254  */
255 nlohmann::json actionParameterValueNotInList(
256     std::string_view arg1, std::string_view arg2, std::string_view arg3)
257 {
258     return getLog(
259         redfish::registries::base::Index::actionParameterValueNotInList,
260         std::to_array({arg1, arg2, arg3}));
261 }
262 
263 void actionParameterValueNotInList(crow::Response& res, std::string_view arg1,
264                                    std::string_view arg2, std::string_view arg3)
265 {
266     res.result(boost::beast::http::status::bad_request);
267     addMessageToErrorJson(res.jsonValue,
268                           actionParameterValueNotInList(arg1, arg2, arg3));
269 }
270 
271 /**
272  * @internal
273  * @brief Formats InternalError message into JSON
274  *
275  * See header file for more information
276  * @endinternal
277  */
278 nlohmann::json internalError()
279 {
280     return getLog(redfish::registries::base::Index::internalError, {});
281 }
282 
283 void internalError(crow::Response& res, const std::source_location location)
284 {
285     BMCWEB_LOG_CRITICAL("Internal Error {}({}:{}) `{}`: ", location.file_name(),
286                         location.line(), location.column(),
287                         location.function_name());
288     res.result(boost::beast::http::status::internal_server_error);
289     addMessageToErrorJson(res.jsonValue, internalError());
290 }
291 
292 /**
293  * @internal
294  * @brief Formats UnrecognizedRequestBody message into JSON
295  *
296  * See header file for more information
297  * @endinternal
298  */
299 nlohmann::json unrecognizedRequestBody()
300 {
301     return getLog(redfish::registries::base::Index::unrecognizedRequestBody,
302                   {});
303 }
304 
305 void unrecognizedRequestBody(crow::Response& res)
306 {
307     res.result(boost::beast::http::status::bad_request);
308     addMessageToErrorJson(res.jsonValue, unrecognizedRequestBody());
309 }
310 
311 /**
312  * @internal
313  * @brief Formats ResourceAtUriUnauthorized message into JSON
314  *
315  * See header file for more information
316  * @endinternal
317  */
318 nlohmann::json resourceAtUriUnauthorized(const boost::urls::url_view_base& arg1,
319                                          std::string_view arg2)
320 {
321     return getLog(redfish::registries::base::Index::resourceAtUriUnauthorized,
322                   std::to_array<std::string_view>({arg1.buffer(), arg2}));
323 }
324 
325 void resourceAtUriUnauthorized(crow::Response& res,
326                                const boost::urls::url_view_base& arg1,
327                                std::string_view arg2)
328 {
329     res.result(boost::beast::http::status::unauthorized);
330     addMessageToErrorJson(res.jsonValue, resourceAtUriUnauthorized(arg1, arg2));
331 }
332 
333 /**
334  * @internal
335  * @brief Formats ActionParameterUnknown message into JSON
336  *
337  * See header file for more information
338  * @endinternal
339  */
340 nlohmann::json actionParameterUnknown(std::string_view arg1,
341                                       std::string_view arg2)
342 {
343     return getLog(redfish::registries::base::Index::actionParameterUnknown,
344                   std::to_array({arg1, arg2}));
345 }
346 
347 void actionParameterUnknown(crow::Response& res, std::string_view arg1,
348                             std::string_view arg2)
349 {
350     res.result(boost::beast::http::status::bad_request);
351     addMessageToErrorJson(res.jsonValue, actionParameterUnknown(arg1, arg2));
352 }
353 
354 /**
355  * @internal
356  * @brief Formats ResourceCannotBeDeleted message into JSON
357  *
358  * See header file for more information
359  * @endinternal
360  */
361 nlohmann::json resourceCannotBeDeleted()
362 {
363     return getLog(redfish::registries::base::Index::resourceCannotBeDeleted,
364                   {});
365 }
366 
367 void resourceCannotBeDeleted(crow::Response& res)
368 {
369     res.result(boost::beast::http::status::method_not_allowed);
370     addMessageToErrorJson(res.jsonValue, resourceCannotBeDeleted());
371 }
372 
373 /**
374  * @internal
375  * @brief Formats PropertyDuplicate message into JSON
376  *
377  * See header file for more information
378  * @endinternal
379  */
380 nlohmann::json propertyDuplicate(std::string_view arg1)
381 {
382     return getLog(redfish::registries::base::Index::propertyDuplicate,
383                   std::to_array({arg1}));
384 }
385 
386 void propertyDuplicate(crow::Response& res, std::string_view arg1)
387 {
388     res.result(boost::beast::http::status::bad_request);
389     addMessageToJson(res.jsonValue, propertyDuplicate(arg1), arg1);
390 }
391 
392 /**
393  * @internal
394  * @brief Formats ServiceTemporarilyUnavailable message into JSON
395  *
396  * See header file for more information
397  * @endinternal
398  */
399 nlohmann::json serviceTemporarilyUnavailable(std::string_view arg1)
400 {
401     return getLog(
402         redfish::registries::base::Index::serviceTemporarilyUnavailable,
403         std::to_array({arg1}));
404 }
405 
406 void serviceTemporarilyUnavailable(crow::Response& res, std::string_view arg1)
407 {
408     res.addHeader(boost::beast::http::field::retry_after, arg1);
409     res.result(boost::beast::http::status::service_unavailable);
410     addMessageToErrorJson(res.jsonValue, serviceTemporarilyUnavailable(arg1));
411 }
412 
413 /**
414  * @internal
415  * @brief Formats ResourceAlreadyExists message into JSON
416  *
417  * See header file for more information
418  * @endinternal
419  */
420 nlohmann::json resourceAlreadyExists(
421     std::string_view arg1, std::string_view arg2, std::string_view arg3)
422 {
423     return getLog(redfish::registries::base::Index::resourceAlreadyExists,
424                   std::to_array({arg1, arg2, arg3}));
425 }
426 
427 void resourceAlreadyExists(crow::Response& res, std::string_view arg1,
428                            std::string_view arg2, std::string_view arg3)
429 {
430     res.result(boost::beast::http::status::bad_request);
431     addMessageToJson(res.jsonValue, resourceAlreadyExists(arg1, arg2, arg3),
432                      arg2);
433 }
434 
435 /**
436  * @internal
437  * @brief Formats AccountForSessionNoLongerExists message into JSON
438  *
439  * See header file for more information
440  * @endinternal
441  */
442 nlohmann::json accountForSessionNoLongerExists()
443 {
444     return getLog(
445         redfish::registries::base::Index::accountForSessionNoLongerExists, {});
446 }
447 
448 void accountForSessionNoLongerExists(crow::Response& res)
449 {
450     res.result(boost::beast::http::status::forbidden);
451     addMessageToErrorJson(res.jsonValue, accountForSessionNoLongerExists());
452 }
453 
454 /**
455  * @internal
456  * @brief Formats CreateFailedMissingReqProperties message into JSON
457  *
458  * See header file for more information
459  * @endinternal
460  */
461 nlohmann::json createFailedMissingReqProperties(std::string_view arg1)
462 {
463     return getLog(
464         redfish::registries::base::Index::createFailedMissingReqProperties,
465         std::to_array({arg1}));
466 }
467 
468 void createFailedMissingReqProperties(crow::Response& res,
469                                       std::string_view arg1)
470 {
471     res.result(boost::beast::http::status::bad_request);
472     addMessageToJson(res.jsonValue, createFailedMissingReqProperties(arg1),
473                      arg1);
474 }
475 
476 /**
477  * @internal
478  * @brief Formats PropertyValueFormatError message into JSON for the specified
479  * property
480  *
481  * See header file for more information
482  * @endinternal
483  */
484 nlohmann::json propertyValueFormatError(const nlohmann::json& arg1,
485                                         std::string_view arg2)
486 {
487     std::string arg1Str =
488         arg1.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
489     return getLog(redfish::registries::base::Index::propertyValueFormatError,
490                   std::to_array<std::string_view>({arg1Str, arg2}));
491 }
492 
493 void propertyValueFormatError(crow::Response& res, const nlohmann::json& arg1,
494                               std::string_view arg2)
495 {
496     res.result(boost::beast::http::status::bad_request);
497     addMessageToJson(res.jsonValue, propertyValueFormatError(arg1, arg2), arg2);
498 }
499 
500 /**
501  * @internal
502  * @brief Formats PropertyValueNotInList message into JSON for the specified
503  * property
504  *
505  * See header file for more information
506  * @endinternal
507  */
508 
509 nlohmann::json propertyValueNotInList(const nlohmann::json& arg1,
510                                       std::string_view arg2)
511 {
512     std::string arg1Str =
513         arg1.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace);
514     return getLog(redfish::registries::base::Index::propertyValueNotInList,
515                   std::to_array<std::string_view>({arg1Str, arg2}));
516 }
517 
518 void propertyValueNotInList(crow::Response& res, const nlohmann::json& arg1,
519                             std::string_view arg2)
520 {
521     res.result(boost::beast::http::status::bad_request);
522     addMessageToJson(res.jsonValue, propertyValueNotInList(arg1, arg2), arg2);
523 }
524 
525 /**
526  * @internal
527  * @brief Formats PropertyValueOutOfRange message into JSON
528  *
529  * See header file for more information
530  * @endinternal
531  */
532 nlohmann::json propertyValueOutOfRange(const nlohmann::json& arg1,
533                                        std::string_view arg2)
534 {
535     std::string arg1Str =
536         arg1.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
537     return getLog(redfish::registries::base::Index::propertyValueOutOfRange,
538                   std::to_array<std::string_view>({arg1Str, arg2}));
539 }
540 
541 void propertyValueOutOfRange(crow::Response& res, const nlohmann::json& arg1,
542                              std::string_view arg2)
543 {
544     res.result(boost::beast::http::status::bad_request);
545     addMessageToErrorJson(res.jsonValue, propertyValueOutOfRange(arg1, arg2));
546 }
547 
548 /**
549  * @internal
550  * @brief Formats ResourceAtUriInUnknownFormat message into JSON
551  *
552  * See header file for more information
553  * @endinternal
554  */
555 nlohmann::json
556     resourceAtUriInUnknownFormat(const boost::urls::url_view_base& arg1)
557 {
558     return getLog(
559         redfish::registries::base::Index::resourceAtUriInUnknownFormat,
560         std::to_array<std::string_view>({arg1.buffer()}));
561 }
562 
563 void resourceAtUriInUnknownFormat(crow::Response& res,
564                                   const boost::urls::url_view_base& arg1)
565 {
566     res.result(boost::beast::http::status::bad_request);
567     addMessageToErrorJson(res.jsonValue, resourceAtUriInUnknownFormat(arg1));
568 }
569 
570 /**
571  * @internal
572  * @brief Formats ServiceDisabled message into JSON
573  *
574  * See header file for more information
575  * @endinternal
576  */
577 nlohmann::json serviceDisabled(std::string_view arg1)
578 {
579     return getLog(redfish::registries::base::Index::serviceDisabled,
580                   std::to_array({arg1}));
581 }
582 
583 void serviceDisabled(crow::Response& res, std::string_view arg1)
584 {
585     res.result(boost::beast::http::status::service_unavailable);
586     addMessageToErrorJson(res.jsonValue, serviceDisabled(arg1));
587 }
588 
589 /**
590  * @internal
591  * @brief Formats ServiceInUnknownState message into JSON
592  *
593  * See header file for more information
594  * @endinternal
595  */
596 nlohmann::json serviceInUnknownState()
597 {
598     return getLog(redfish::registries::base::Index::serviceInUnknownState, {});
599 }
600 
601 void serviceInUnknownState(crow::Response& res)
602 {
603     res.result(boost::beast::http::status::service_unavailable);
604     addMessageToErrorJson(res.jsonValue, serviceInUnknownState());
605 }
606 
607 /**
608  * @internal
609  * @brief Formats EventSubscriptionLimitExceeded message into JSON
610  *
611  * See header file for more information
612  * @endinternal
613  */
614 nlohmann::json eventSubscriptionLimitExceeded()
615 {
616     return getLog(
617         redfish::registries::base::Index::eventSubscriptionLimitExceeded, {});
618 }
619 
620 void eventSubscriptionLimitExceeded(crow::Response& res)
621 {
622     res.result(boost::beast::http::status::service_unavailable);
623     addMessageToErrorJson(res.jsonValue, eventSubscriptionLimitExceeded());
624 }
625 
626 /**
627  * @internal
628  * @brief Formats ActionParameterMissing message into JSON
629  *
630  * See header file for more information
631  * @endinternal
632  */
633 nlohmann::json actionParameterMissing(std::string_view arg1,
634                                       std::string_view arg2)
635 {
636     return getLog(redfish::registries::base::Index::actionParameterMissing,
637                   std::to_array({arg1, arg2}));
638 }
639 
640 void actionParameterMissing(crow::Response& res, std::string_view arg1,
641                             std::string_view arg2)
642 {
643     res.result(boost::beast::http::status::bad_request);
644     addMessageToErrorJson(res.jsonValue, actionParameterMissing(arg1, arg2));
645 }
646 
647 /**
648  * @internal
649  * @brief Formats StringValueTooLong message into JSON
650  *
651  * See header file for more information
652  * @endinternal
653  */
654 nlohmann::json stringValueTooLong(std::string_view arg1, int arg2)
655 {
656     std::string arg2String = std::to_string(arg2);
657     return getLog(redfish::registries::base::Index::stringValueTooLong,
658                   std::to_array({arg1, std::string_view(arg2String)}));
659 }
660 
661 void stringValueTooLong(crow::Response& res, std::string_view arg1, int arg2)
662 {
663     res.result(boost::beast::http::status::bad_request);
664     addMessageToErrorJson(res.jsonValue, stringValueTooLong(arg1, arg2));
665 }
666 
667 /**
668  * @internal
669  * @brief Formats SessionTerminated message into JSON
670  *
671  * See header file for more information
672  * @endinternal
673  */
674 nlohmann::json sessionTerminated()
675 {
676     return getLog(redfish::registries::base::Index::sessionTerminated, {});
677 }
678 
679 void sessionTerminated(crow::Response& res)
680 {
681     res.result(boost::beast::http::status::ok);
682     addMessageToJsonRoot(res.jsonValue, sessionTerminated());
683 }
684 
685 /**
686  * @internal
687  * @brief Formats SubscriptionTerminated message into JSON
688  *
689  * See header file for more information
690  * @endinternal
691  */
692 nlohmann::json subscriptionTerminated()
693 {
694     return getLog(redfish::registries::base::Index::subscriptionTerminated, {});
695 }
696 
697 void subscriptionTerminated(crow::Response& res)
698 {
699     res.result(boost::beast::http::status::ok);
700     addMessageToJsonRoot(res.jsonValue, subscriptionTerminated());
701 }
702 
703 /**
704  * @internal
705  * @brief Formats ResourceTypeIncompatible message into JSON
706  *
707  * See header file for more information
708  * @endinternal
709  */
710 nlohmann::json resourceTypeIncompatible(std::string_view arg1,
711                                         std::string_view arg2)
712 {
713     return getLog(redfish::registries::base::Index::resourceTypeIncompatible,
714                   std::to_array({arg1, arg2}));
715 }
716 
717 void resourceTypeIncompatible(crow::Response& res, std::string_view arg1,
718                               std::string_view arg2)
719 {
720     res.result(boost::beast::http::status::bad_request);
721     addMessageToErrorJson(res.jsonValue, resourceTypeIncompatible(arg1, arg2));
722 }
723 
724 /**
725  * @internal
726  * @brief Formats ResetRequired message into JSON
727  *
728  * See header file for more information
729  * @endinternal
730  */
731 nlohmann::json resetRequired(const boost::urls::url_view_base& arg1,
732                              std::string_view arg2)
733 {
734     return getLog(redfish::registries::base::Index::resetRequired,
735                   std::to_array<std::string_view>({arg1.buffer(), arg2}));
736 }
737 
738 void resetRequired(crow::Response& res, const boost::urls::url_view_base& arg1,
739                    std::string_view arg2)
740 {
741     res.result(boost::beast::http::status::bad_request);
742     addMessageToErrorJson(res.jsonValue, resetRequired(arg1, arg2));
743 }
744 
745 /**
746  * @internal
747  * @brief Formats ChassisPowerStateOnRequired message into JSON
748  *
749  * See header file for more information
750  * @endinternal
751  */
752 nlohmann::json chassisPowerStateOnRequired(std::string_view arg1)
753 {
754     return getLog(redfish::registries::base::Index::resetRequired,
755                   std::to_array({arg1}));
756 }
757 
758 void chassisPowerStateOnRequired(crow::Response& res, std::string_view arg1)
759 {
760     res.result(boost::beast::http::status::bad_request);
761     addMessageToErrorJson(res.jsonValue, chassisPowerStateOnRequired(arg1));
762 }
763 
764 /**
765  * @internal
766  * @brief Formats ChassisPowerStateOffRequired message into JSON
767  *
768  * See header file for more information
769  * @endinternal
770  */
771 nlohmann::json chassisPowerStateOffRequired(std::string_view arg1)
772 {
773     return getLog(
774         redfish::registries::base::Index::chassisPowerStateOffRequired,
775         std::to_array({arg1}));
776 }
777 
778 void chassisPowerStateOffRequired(crow::Response& res, std::string_view arg1)
779 {
780     res.result(boost::beast::http::status::bad_request);
781     addMessageToErrorJson(res.jsonValue, chassisPowerStateOffRequired(arg1));
782 }
783 
784 /**
785  * @internal
786  * @brief Formats PropertyValueConflict message into JSON
787  *
788  * See header file for more information
789  * @endinternal
790  */
791 nlohmann::json propertyValueConflict(std::string_view arg1,
792                                      std::string_view arg2)
793 {
794     return getLog(redfish::registries::base::Index::propertyValueConflict,
795                   std::to_array({arg1, arg2}));
796 }
797 
798 void propertyValueConflict(crow::Response& res, std::string_view arg1,
799                            std::string_view arg2)
800 {
801     res.result(boost::beast::http::status::bad_request);
802     addMessageToErrorJson(res.jsonValue, propertyValueConflict(arg1, arg2));
803 }
804 
805 /**
806  * @internal
807  * @brief Formats PropertyValueResourceConflict message into JSON
808  *
809  * See header file for more information
810  * @endinternal
811  */
812 nlohmann::json propertyValueResourceConflict(
813     std::string_view arg1, const nlohmann::json& arg2,
814     const boost::urls::url_view_base& arg3)
815 {
816     std::string arg2Str =
817         arg2.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
818 
819     return getLog(
820         redfish::registries::base::Index::propertyValueResourceConflict,
821         std::to_array<std::string_view>({arg1, arg2Str, arg3.buffer()}));
822 }
823 
824 void propertyValueResourceConflict(crow::Response& res, std::string_view arg1,
825                                    const nlohmann::json& arg2,
826                                    const boost::urls::url_view_base& arg3)
827 {
828     res.result(boost::beast::http::status::conflict);
829     addMessageToErrorJson(res.jsonValue,
830                           propertyValueResourceConflict(arg1, arg2, arg3));
831 }
832 
833 /**
834  * @internal
835  * @brief Formats PropertyValueExternalConflict message into JSON
836  *
837  * See header file for more information
838  * @endinternal
839  */
840 nlohmann::json propertyValueExternalConflict(std::string_view arg1,
841                                              const nlohmann::json& arg2)
842 {
843     std::string arg2Str =
844         arg2.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
845 
846     return getLog(
847         redfish::registries::base::Index::propertyValueExternalConflict,
848         std::to_array<std::string_view>({arg1, arg2Str}));
849 }
850 
851 void propertyValueExternalConflict(crow::Response& res, std::string_view arg1,
852                                    const nlohmann::json& arg2)
853 {
854     res.result(boost::beast::http::status::conflict);
855     addMessageToErrorJson(res.jsonValue,
856                           propertyValueExternalConflict(arg1, arg2));
857 }
858 
859 /**
860  * @internal
861  * @brief Formats PropertyValueIncorrect message into JSON
862  *
863  * See header file for more information
864  * @endinternal
865  */
866 nlohmann::json propertyValueIncorrect(std::string_view arg1,
867                                       const nlohmann::json& arg2)
868 {
869     std::string arg2Str =
870         arg2.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
871     return getLog(redfish::registries::base::Index::propertyValueIncorrect,
872                   std::to_array<std::string_view>({arg1, arg2Str}));
873 }
874 
875 void propertyValueIncorrect(crow::Response& res, std::string_view arg1,
876                             const nlohmann::json& arg2)
877 {
878     res.result(boost::beast::http::status::bad_request);
879     addMessageToErrorJson(res.jsonValue, propertyValueIncorrect(arg1, arg2));
880 }
881 
882 /**
883  * @internal
884  * @brief Formats ResourceCreationConflict message into JSON
885  *
886  * See header file for more information
887  * @endinternal
888  */
889 nlohmann::json resourceCreationConflict(const boost::urls::url_view_base& arg1)
890 {
891     return getLog(redfish::registries::base::Index::resourceCreationConflict,
892                   std::to_array<std::string_view>({arg1.buffer()}));
893 }
894 
895 void resourceCreationConflict(crow::Response& res,
896                               const boost::urls::url_view_base& arg1)
897 {
898     res.result(boost::beast::http::status::bad_request);
899     addMessageToErrorJson(res.jsonValue, resourceCreationConflict(arg1));
900 }
901 
902 /**
903  * @internal
904  * @brief Formats MaximumErrorsExceeded message into JSON
905  *
906  * See header file for more information
907  * @endinternal
908  */
909 nlohmann::json maximumErrorsExceeded()
910 {
911     return getLog(redfish::registries::base::Index::maximumErrorsExceeded, {});
912 }
913 
914 void maximumErrorsExceeded(crow::Response& res)
915 {
916     res.result(boost::beast::http::status::internal_server_error);
917     addMessageToErrorJson(res.jsonValue, maximumErrorsExceeded());
918 }
919 
920 /**
921  * @internal
922  * @brief Formats PreconditionFailed message into JSON
923  *
924  * See header file for more information
925  * @endinternal
926  */
927 nlohmann::json preconditionFailed()
928 {
929     return getLog(redfish::registries::base::Index::preconditionFailed, {});
930 }
931 
932 void preconditionFailed(crow::Response& res)
933 {
934     res.result(boost::beast::http::status::precondition_failed);
935     addMessageToErrorJson(res.jsonValue, preconditionFailed());
936 }
937 
938 /**
939  * @internal
940  * @brief Formats PreconditionRequired message into JSON
941  *
942  * See header file for more information
943  * @endinternal
944  */
945 nlohmann::json preconditionRequired()
946 {
947     return getLog(redfish::registries::base::Index::preconditionRequired, {});
948 }
949 
950 void preconditionRequired(crow::Response& res)
951 {
952     res.result(boost::beast::http::status::bad_request);
953     addMessageToErrorJson(res.jsonValue, preconditionRequired());
954 }
955 
956 /**
957  * @internal
958  * @brief Formats OperationFailed message into JSON
959  *
960  * See header file for more information
961  * @endinternal
962  */
963 nlohmann::json operationFailed()
964 {
965     return getLog(redfish::registries::base::Index::operationFailed, {});
966 }
967 
968 void operationFailed(crow::Response& res)
969 {
970     res.result(boost::beast::http::status::bad_gateway);
971     addMessageToErrorJson(res.jsonValue, operationFailed());
972 }
973 
974 /**
975  * @internal
976  * @brief Formats OperationTimeout message into JSON
977  *
978  * See header file for more information
979  * @endinternal
980  */
981 nlohmann::json operationTimeout()
982 {
983     return getLog(redfish::registries::base::Index::operationTimeout, {});
984 }
985 
986 void operationTimeout(crow::Response& res)
987 {
988     res.result(boost::beast::http::status::internal_server_error);
989     addMessageToErrorJson(res.jsonValue, operationTimeout());
990 }
991 
992 /**
993  * @internal
994  * @brief Formats PropertyValueTypeError message into JSON for the specified
995  * property
996  *
997  * See header file for more information
998  * @endinternal
999  */
1000 nlohmann::json propertyValueTypeError(const nlohmann::json& arg1,
1001                                       std::string_view arg2)
1002 {
1003     std::string arg1Str =
1004         arg1.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
1005     return getLog(redfish::registries::base::Index::propertyValueTypeError,
1006                   std::to_array<std::string_view>({arg1Str, arg2}));
1007 }
1008 
1009 void propertyValueTypeError(crow::Response& res, const nlohmann::json& arg1,
1010                             std::string_view arg2)
1011 {
1012     res.result(boost::beast::http::status::bad_request);
1013     addMessageToJson(res.jsonValue, propertyValueTypeError(arg1, arg2), arg2);
1014 }
1015 
1016 /**
1017  * @internal
1018  * @brief Formats PropertyValueError message into JSON for the specified
1019  * property
1020  *
1021  * See header file for more information
1022  * @endinternal
1023  */
1024 nlohmann::json propertyValueError(std::string_view arg1)
1025 {
1026     return getLog(redfish::registries::base::Index::propertyValueError,
1027                   std::to_array<std::string_view>({arg1}));
1028 }
1029 
1030 void propertyValueError(crow::Response& res, std::string_view arg1)
1031 {
1032     res.result(boost::beast::http::status::bad_request);
1033     addMessageToJson(res.jsonValue, propertyValueError(arg1), arg1);
1034 }
1035 
1036 /**
1037  * @internal
1038  * @brief Formats ResourceNotFound message into JSONd
1039  *
1040  * See header file for more information
1041  * @endinternal
1042  */
1043 nlohmann::json resourceNotFound(std::string_view arg1, std::string_view arg2)
1044 {
1045     return getLog(redfish::registries::base::Index::resourceNotFound,
1046                   std::to_array({arg1, arg2}));
1047 }
1048 
1049 void resourceNotFound(crow::Response& res, std::string_view arg1,
1050                       std::string_view arg2)
1051 {
1052     res.result(boost::beast::http::status::not_found);
1053     addMessageToErrorJson(res.jsonValue, resourceNotFound(arg1, arg2));
1054 }
1055 
1056 /**
1057  * @internal
1058  * @brief Formats CouldNotEstablishConnection message into JSON
1059  *
1060  * See header file for more information
1061  * @endinternal
1062  */
1063 nlohmann::json
1064     couldNotEstablishConnection(const boost::urls::url_view_base& arg1)
1065 {
1066     return getLog(redfish::registries::base::Index::couldNotEstablishConnection,
1067                   std::to_array<std::string_view>({arg1.buffer()}));
1068 }
1069 
1070 void couldNotEstablishConnection(crow::Response& res,
1071                                  const boost::urls::url_view_base& arg1)
1072 {
1073     res.result(boost::beast::http::status::not_found);
1074     addMessageToErrorJson(res.jsonValue, couldNotEstablishConnection(arg1));
1075 }
1076 
1077 /**
1078  * @internal
1079  * @brief Formats PropertyNotWritable message into JSON for the specified
1080  * property
1081  *
1082  * See header file for more information
1083  * @endinternal
1084  */
1085 nlohmann::json propertyNotWritable(std::string_view arg1)
1086 {
1087     return getLog(redfish::registries::base::Index::propertyNotWritable,
1088                   std::to_array({arg1}));
1089 }
1090 
1091 void propertyNotWritable(crow::Response& res, std::string_view arg1)
1092 {
1093     res.result(boost::beast::http::status::forbidden);
1094     addMessageToJson(res.jsonValue, propertyNotWritable(arg1), arg1);
1095 }
1096 
1097 /**
1098  * @internal
1099  * @brief Formats QueryParameterValueTypeError message into JSON
1100  *
1101  * See header file for more information
1102  * @endinternal
1103  */
1104 nlohmann::json queryParameterValueTypeError(const nlohmann::json& arg1,
1105                                             std::string_view arg2)
1106 {
1107     std::string arg1Str =
1108         arg1.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
1109     return getLog(
1110         redfish::registries::base::Index::queryParameterValueTypeError,
1111         std::to_array<std::string_view>({arg1Str, arg2}));
1112 }
1113 
1114 void queryParameterValueTypeError(
1115     crow::Response& res, const nlohmann::json& arg1, std::string_view arg2)
1116 {
1117     res.result(boost::beast::http::status::bad_request);
1118     addMessageToErrorJson(res.jsonValue,
1119                           queryParameterValueTypeError(arg1, arg2));
1120 }
1121 
1122 /**
1123  * @internal
1124  * @brief Formats ServiceShuttingDown message into JSON
1125  *
1126  * See header file for more information
1127  * @endinternal
1128  */
1129 nlohmann::json serviceShuttingDown()
1130 {
1131     return getLog(redfish::registries::base::Index::serviceShuttingDown, {});
1132 }
1133 
1134 void serviceShuttingDown(crow::Response& res)
1135 {
1136     res.result(boost::beast::http::status::service_unavailable);
1137     addMessageToErrorJson(res.jsonValue, serviceShuttingDown());
1138 }
1139 
1140 /**
1141  * @internal
1142  * @brief Formats ActionParameterDuplicate message into JSON
1143  *
1144  * See header file for more information
1145  * @endinternal
1146  */
1147 nlohmann::json actionParameterDuplicate(std::string_view arg1,
1148                                         std::string_view arg2)
1149 {
1150     return getLog(redfish::registries::base::Index::actionParameterDuplicate,
1151                   std::to_array({arg1, arg2}));
1152 }
1153 
1154 void actionParameterDuplicate(crow::Response& res, std::string_view arg1,
1155                               std::string_view arg2)
1156 {
1157     res.result(boost::beast::http::status::bad_request);
1158     addMessageToErrorJson(res.jsonValue, actionParameterDuplicate(arg1, arg2));
1159 }
1160 
1161 /**
1162  * @internal
1163  * @brief Formats ActionParameterNotSupported message into JSON
1164  *
1165  * See header file for more information
1166  * @endinternal
1167  */
1168 nlohmann::json actionParameterNotSupported(std::string_view arg1,
1169                                            std::string_view arg2)
1170 {
1171     return getLog(redfish::registries::base::Index::actionParameterNotSupported,
1172                   std::to_array({arg1, arg2}));
1173 }
1174 
1175 void actionParameterNotSupported(crow::Response& res, std::string_view arg1,
1176                                  std::string_view arg2)
1177 {
1178     res.result(boost::beast::http::status::bad_request);
1179     addMessageToErrorJson(res.jsonValue,
1180                           actionParameterNotSupported(arg1, arg2));
1181 }
1182 
1183 /**
1184  * @internal
1185  * @brief Formats SourceDoesNotSupportProtocol message into JSON
1186  *
1187  * See header file for more information
1188  * @endinternal
1189  */
1190 nlohmann::json sourceDoesNotSupportProtocol(
1191     const boost::urls::url_view_base& arg1, std::string_view arg2)
1192 {
1193     return getLog(
1194         redfish::registries::base::Index::sourceDoesNotSupportProtocol,
1195         std::to_array<std::string_view>({arg1.buffer(), arg2}));
1196 }
1197 
1198 void sourceDoesNotSupportProtocol(crow::Response& res,
1199                                   const boost::urls::url_view_base& arg1,
1200                                   std::string_view arg2)
1201 {
1202     res.result(boost::beast::http::status::bad_request);
1203     addMessageToErrorJson(res.jsonValue,
1204                           sourceDoesNotSupportProtocol(arg1, arg2));
1205 }
1206 
1207 /**
1208  * @internal
1209  * @brief Formats StrictAccountTypes message into JSON
1210  *
1211  * See header file for more information
1212  * @endinternal
1213  */
1214 nlohmann::json strictAccountTypes(std::string_view arg1)
1215 {
1216     return getLog(redfish::registries::base::Index::strictAccountTypes,
1217                   std::to_array({arg1}));
1218 }
1219 
1220 void strictAccountTypes(crow::Response& res, std::string_view arg1)
1221 {
1222     res.result(boost::beast::http::status::bad_request);
1223     addMessageToErrorJson(res.jsonValue, strictAccountTypes(arg1));
1224 }
1225 
1226 /**
1227  * @internal
1228  * @brief Formats AccountRemoved message into JSON
1229  *
1230  * See header file for more information
1231  * @endinternal
1232  */
1233 nlohmann::json accountRemoved()
1234 {
1235     return getLog(redfish::registries::base::Index::accountRemoved, {});
1236 }
1237 
1238 void accountRemoved(crow::Response& res)
1239 {
1240     res.result(boost::beast::http::status::ok);
1241     addMessageToJsonRoot(res.jsonValue, accountRemoved());
1242 }
1243 
1244 /**
1245  * @internal
1246  * @brief Formats AccessDenied message into JSON
1247  *
1248  * See header file for more information
1249  * @endinternal
1250  */
1251 nlohmann::json accessDenied(const boost::urls::url_view_base& arg1)
1252 {
1253     return getLog(redfish::registries::base::Index::accessDenied,
1254                   std::to_array<std::string_view>({arg1.buffer()}));
1255 }
1256 
1257 void accessDenied(crow::Response& res, const boost::urls::url_view_base& arg1)
1258 {
1259     res.result(boost::beast::http::status::forbidden);
1260     addMessageToErrorJson(res.jsonValue, accessDenied(arg1));
1261 }
1262 
1263 /**
1264  * @internal
1265  * @brief Formats QueryNotSupported message into JSON
1266  *
1267  * See header file for more information
1268  * @endinternal
1269  */
1270 nlohmann::json queryNotSupported()
1271 {
1272     return getLog(redfish::registries::base::Index::queryNotSupported, {});
1273 }
1274 
1275 void queryNotSupported(crow::Response& res)
1276 {
1277     res.result(boost::beast::http::status::bad_request);
1278     addMessageToErrorJson(res.jsonValue, queryNotSupported());
1279 }
1280 
1281 /**
1282  * @internal
1283  * @brief Formats CreateLimitReachedForResource message into JSON
1284  *
1285  * See header file for more information
1286  * @endinternal
1287  */
1288 nlohmann::json createLimitReachedForResource()
1289 {
1290     return getLog(
1291         redfish::registries::base::Index::createLimitReachedForResource, {});
1292 }
1293 
1294 void createLimitReachedForResource(crow::Response& res)
1295 {
1296     res.result(boost::beast::http::status::bad_request);
1297     addMessageToErrorJson(res.jsonValue, createLimitReachedForResource());
1298 }
1299 
1300 /**
1301  * @internal
1302  * @brief Formats GeneralError message into JSON
1303  *
1304  * See header file for more information
1305  * @endinternal
1306  */
1307 nlohmann::json generalError()
1308 {
1309     return getLog(redfish::registries::base::Index::generalError, {});
1310 }
1311 
1312 void generalError(crow::Response& res)
1313 {
1314     res.result(boost::beast::http::status::internal_server_error);
1315     addMessageToErrorJson(res.jsonValue, generalError());
1316 }
1317 
1318 /**
1319  * @internal
1320  * @brief Formats Success message into JSON
1321  *
1322  * See header file for more information
1323  * @endinternal
1324  */
1325 nlohmann::json success()
1326 {
1327     return getLog(redfish::registries::base::Index::success, {});
1328 }
1329 
1330 void success(crow::Response& res)
1331 {
1332     // don't set res.result here because success is the default and any
1333     // error should overwrite the default
1334     addMessageToJsonRoot(res.jsonValue, success());
1335 }
1336 
1337 /**
1338  * @internal
1339  * @brief Formats Created message into JSON
1340  *
1341  * See header file for more information
1342  * @endinternal
1343  */
1344 nlohmann::json created()
1345 {
1346     return getLog(redfish::registries::base::Index::created, {});
1347 }
1348 
1349 void created(crow::Response& res)
1350 {
1351     res.result(boost::beast::http::status::created);
1352     addMessageToJsonRoot(res.jsonValue, created());
1353 }
1354 
1355 /**
1356  * @internal
1357  * @brief Formats NoOperation message into JSON
1358  *
1359  * See header file for more information
1360  * @endinternal
1361  */
1362 nlohmann::json noOperation()
1363 {
1364     return getLog(redfish::registries::base::Index::noOperation, {});
1365 }
1366 
1367 void noOperation(crow::Response& res)
1368 {
1369     res.result(boost::beast::http::status::bad_request);
1370     addMessageToErrorJson(res.jsonValue, noOperation());
1371 }
1372 
1373 /**
1374  * @internal
1375  * @brief Formats PropertyUnknown message into JSON for the specified
1376  * property
1377  *
1378  * See header file for more information
1379  * @endinternal
1380  */
1381 nlohmann::json propertyUnknown(std::string_view arg1)
1382 {
1383     return getLog(redfish::registries::base::Index::propertyUnknown,
1384                   std::to_array({arg1}));
1385 }
1386 
1387 void propertyUnknown(crow::Response& res, std::string_view arg1)
1388 {
1389     res.result(boost::beast::http::status::bad_request);
1390     addMessageToErrorJson(res.jsonValue, propertyUnknown(arg1));
1391 }
1392 
1393 /**
1394  * @internal
1395  * @brief Formats NoValidSession message into JSON
1396  *
1397  * See header file for more information
1398  * @endinternal
1399  */
1400 nlohmann::json noValidSession()
1401 {
1402     return getLog(redfish::registries::base::Index::noValidSession, {});
1403 }
1404 
1405 void noValidSession(crow::Response& res)
1406 {
1407     res.result(boost::beast::http::status::forbidden);
1408     addMessageToErrorJson(res.jsonValue, noValidSession());
1409 }
1410 
1411 /**
1412  * @internal
1413  * @brief Formats InvalidObject message into JSON
1414  *
1415  * See header file for more information
1416  * @endinternal
1417  */
1418 nlohmann::json invalidObject(const boost::urls::url_view_base& arg1)
1419 {
1420     return getLog(redfish::registries::base::Index::invalidObject,
1421                   std::to_array<std::string_view>({arg1.buffer()}));
1422 }
1423 
1424 void invalidObject(crow::Response& res, const boost::urls::url_view_base& arg1)
1425 {
1426     res.result(boost::beast::http::status::bad_request);
1427     addMessageToErrorJson(res.jsonValue, invalidObject(arg1));
1428 }
1429 
1430 /**
1431  * @internal
1432  * @brief Formats ResourceInStandby message into JSON
1433  *
1434  * See header file for more information
1435  * @endinternal
1436  */
1437 nlohmann::json resourceInStandby()
1438 {
1439     return getLog(redfish::registries::base::Index::resourceInStandby, {});
1440 }
1441 
1442 void resourceInStandby(crow::Response& res)
1443 {
1444     res.result(boost::beast::http::status::service_unavailable);
1445     addMessageToErrorJson(res.jsonValue, resourceInStandby());
1446 }
1447 
1448 /**
1449  * @internal
1450  * @brief Formats ActionParameterValueTypeError message into JSON
1451  *
1452  * See header file for more information
1453  * @endinternal
1454  */
1455 nlohmann::json actionParameterValueTypeError(
1456     const nlohmann::json& arg1, std::string_view arg2, std::string_view arg3)
1457 {
1458     std::string arg1Str =
1459         arg1.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
1460     return getLog(
1461         redfish::registries::base::Index::actionParameterValueTypeError,
1462         std::to_array<std::string_view>({arg1Str, arg2, arg3}));
1463 }
1464 
1465 void actionParameterValueTypeError(crow::Response& res,
1466                                    const nlohmann::json& arg1,
1467                                    std::string_view arg2, std::string_view arg3)
1468 {
1469     res.result(boost::beast::http::status::bad_request);
1470     addMessageToErrorJson(res.jsonValue,
1471                           actionParameterValueTypeError(arg1, arg2, arg3));
1472 }
1473 
1474 /**
1475  * @internal
1476  * @brief Formats actionParameterValueError message into JSON
1477  *
1478  * See header file for more information
1479  * @endinternal
1480  */
1481 nlohmann::json actionParameterValueError(const nlohmann::json& arg1,
1482                                          std::string_view arg2)
1483 {
1484     std::string arg1Str =
1485         arg1.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
1486     return getLog(redfish::registries::base::Index::actionParameterValueError,
1487                   std::to_array<std::string_view>({arg1Str, arg2}));
1488 }
1489 
1490 void actionParameterValueError(crow::Response& res, const nlohmann::json& arg1,
1491                                std::string_view arg2)
1492 {
1493     res.result(boost::beast::http::status::bad_request);
1494     addMessageToErrorJson(res.jsonValue, actionParameterValueError(arg1, arg2));
1495 }
1496 
1497 /**
1498  * @internal
1499  * @brief Formats SessionLimitExceeded message into JSON
1500  *
1501  * See header file for more information
1502  * @endinternal
1503  */
1504 nlohmann::json sessionLimitExceeded()
1505 {
1506     return getLog(redfish::registries::base::Index::sessionLimitExceeded, {});
1507 }
1508 
1509 void sessionLimitExceeded(crow::Response& res)
1510 {
1511     res.result(boost::beast::http::status::service_unavailable);
1512     addMessageToErrorJson(res.jsonValue, sessionLimitExceeded());
1513 }
1514 
1515 /**
1516  * @internal
1517  * @brief Formats ActionNotSupported message into JSON
1518  *
1519  * See header file for more information
1520  * @endinternal
1521  */
1522 nlohmann::json actionNotSupported(std::string_view arg1)
1523 {
1524     return getLog(redfish::registries::base::Index::actionNotSupported,
1525                   std::to_array({arg1}));
1526 }
1527 
1528 void actionNotSupported(crow::Response& res, std::string_view arg1)
1529 {
1530     res.result(boost::beast::http::status::bad_request);
1531     addMessageToErrorJson(res.jsonValue, actionNotSupported(arg1));
1532 }
1533 
1534 /**
1535  * @internal
1536  * @brief Formats InvalidIndex message into JSON
1537  *
1538  * See header file for more information
1539  * @endinternal
1540  */
1541 nlohmann::json invalidIndex(int64_t arg1)
1542 {
1543     std::string arg1Str = std::to_string(arg1);
1544     return getLog(redfish::registries::base::Index::invalidIndex,
1545                   std::to_array<std::string_view>({arg1Str}));
1546 }
1547 
1548 void invalidIndex(crow::Response& res, int64_t arg1)
1549 {
1550     res.result(boost::beast::http::status::bad_request);
1551     addMessageToErrorJson(res.jsonValue, invalidIndex(arg1));
1552 }
1553 
1554 /**
1555  * @internal
1556  * @brief Formats EmptyJSON message into JSON
1557  *
1558  * See header file for more information
1559  * @endinternal
1560  */
1561 nlohmann::json emptyJSON()
1562 {
1563     return getLog(redfish::registries::base::Index::emptyJSON, {});
1564 }
1565 
1566 void emptyJSON(crow::Response& res)
1567 {
1568     res.result(boost::beast::http::status::bad_request);
1569     addMessageToErrorJson(res.jsonValue, emptyJSON());
1570 }
1571 
1572 /**
1573  * @internal
1574  * @brief Formats QueryNotSupportedOnResource message into JSON
1575  *
1576  * See header file for more information
1577  * @endinternal
1578  */
1579 nlohmann::json queryNotSupportedOnResource()
1580 {
1581     return getLog(redfish::registries::base::Index::queryNotSupportedOnResource,
1582                   {});
1583 }
1584 
1585 void queryNotSupportedOnResource(crow::Response& res)
1586 {
1587     res.result(boost::beast::http::status::bad_request);
1588     addMessageToErrorJson(res.jsonValue, queryNotSupportedOnResource());
1589 }
1590 
1591 /**
1592  * @internal
1593  * @brief Formats QueryNotSupportedOnOperation message into JSON
1594  *
1595  * See header file for more information
1596  * @endinternal
1597  */
1598 nlohmann::json queryNotSupportedOnOperation()
1599 {
1600     return getLog(
1601         redfish::registries::base::Index::queryNotSupportedOnOperation, {});
1602 }
1603 
1604 void queryNotSupportedOnOperation(crow::Response& res)
1605 {
1606     res.result(boost::beast::http::status::bad_request);
1607     addMessageToErrorJson(res.jsonValue, queryNotSupportedOnOperation());
1608 }
1609 
1610 /**
1611  * @internal
1612  * @brief Formats QueryCombinationInvalid message into JSON
1613  *
1614  * See header file for more information
1615  * @endinternal
1616  */
1617 nlohmann::json queryCombinationInvalid()
1618 {
1619     return getLog(redfish::registries::base::Index::queryCombinationInvalid,
1620                   {});
1621 }
1622 
1623 void queryCombinationInvalid(crow::Response& res)
1624 {
1625     res.result(boost::beast::http::status::bad_request);
1626     addMessageToErrorJson(res.jsonValue, queryCombinationInvalid());
1627 }
1628 
1629 /**
1630  * @internal
1631  * @brief Formats EventBufferExceeded message into JSON
1632  *
1633  * See header file for more information
1634  * @endinternal
1635  */
1636 nlohmann::json eventBufferExceeded()
1637 {
1638     return getLog(redfish::registries::base::Index::eventBufferExceeded, {});
1639 }
1640 
1641 void eventBufferExceeded(crow::Response& res)
1642 {
1643     res.result(boost::beast::http::status::bad_request);
1644     addMessageToErrorJson(res.jsonValue, eventBufferExceeded());
1645 }
1646 
1647 /**
1648  * @internal
1649  * @brief Formats InsufficientPrivilege message into JSON
1650  *
1651  * See header file for more information
1652  * @endinternal
1653  */
1654 nlohmann::json insufficientPrivilege()
1655 {
1656     return getLog(redfish::registries::base::Index::insufficientPrivilege, {});
1657 }
1658 
1659 void insufficientPrivilege(crow::Response& res)
1660 {
1661     res.result(boost::beast::http::status::forbidden);
1662     addMessageToErrorJson(res.jsonValue, insufficientPrivilege());
1663 }
1664 
1665 /**
1666  * @internal
1667  * @brief Formats PropertyValueModified message into JSON
1668  *
1669  * See header file for more information
1670  * @endinternal
1671  */
1672 nlohmann::json propertyValueModified(std::string_view arg1,
1673                                      const nlohmann::json& arg2)
1674 {
1675     std::string arg2Str =
1676         arg2.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
1677     return getLog(redfish::registries::base::Index::propertyValueModified,
1678                   std::to_array<std::string_view>({arg1, arg2Str}));
1679 }
1680 
1681 void propertyValueModified(crow::Response& res, std::string_view arg1,
1682                            const nlohmann::json& arg2)
1683 {
1684     res.result(boost::beast::http::status::ok);
1685     addMessageToJson(res.jsonValue, propertyValueModified(arg1, arg2), arg1);
1686 }
1687 
1688 /**
1689  * @internal
1690  * @brief Formats AccountNotModified message into JSON
1691  *
1692  * See header file for more information
1693  * @endinternal
1694  */
1695 nlohmann::json accountNotModified()
1696 {
1697     return getLog(redfish::registries::base::Index::accountNotModified, {});
1698 }
1699 
1700 void accountNotModified(crow::Response& res)
1701 {
1702     res.result(boost::beast::http::status::bad_request);
1703     addMessageToErrorJson(res.jsonValue, accountNotModified());
1704 }
1705 
1706 /**
1707  * @internal
1708  * @brief Formats QueryParameterValueFormatError message into JSON
1709  *
1710  * See header file for more information
1711  * @endinternal
1712  */
1713 nlohmann::json queryParameterValueFormatError(const nlohmann::json& arg1,
1714                                               std::string_view arg2)
1715 {
1716     std::string arg1Str =
1717         arg1.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
1718     return getLog(
1719         redfish::registries::base::Index::queryParameterValueFormatError,
1720         std::to_array<std::string_view>({arg1Str, arg2}));
1721 }
1722 
1723 void queryParameterValueFormatError(
1724     crow::Response& res, const nlohmann::json& arg1, std::string_view arg2)
1725 {
1726     res.result(boost::beast::http::status::bad_request);
1727     addMessageToErrorJson(res.jsonValue,
1728                           queryParameterValueFormatError(arg1, arg2));
1729 }
1730 
1731 /**
1732  * @internal
1733  * @brief Formats PropertyMissing message into JSON for the specified
1734  * property
1735  *
1736  * See header file for more information
1737  * @endinternal
1738  */
1739 nlohmann::json propertyMissing(std::string_view arg1)
1740 {
1741     return getLog(redfish::registries::base::Index::propertyMissing,
1742                   std::to_array({arg1}));
1743 }
1744 
1745 void propertyMissing(crow::Response& res, std::string_view arg1)
1746 {
1747     res.result(boost::beast::http::status::bad_request);
1748     addMessageToJson(res.jsonValue, propertyMissing(arg1), arg1);
1749 }
1750 
1751 /**
1752  * @internal
1753  * @brief Formats ResourceExhaustion message into JSON
1754  *
1755  * See header file for more information
1756  * @endinternal
1757  */
1758 nlohmann::json resourceExhaustion(std::string_view arg1)
1759 {
1760     return getLog(redfish::registries::base::Index::resourceExhaustion,
1761                   std::to_array({arg1}));
1762 }
1763 
1764 void resourceExhaustion(crow::Response& res, std::string_view arg1)
1765 {
1766     res.result(boost::beast::http::status::service_unavailable);
1767     addMessageToErrorJson(res.jsonValue, resourceExhaustion(arg1));
1768 }
1769 
1770 /**
1771  * @internal
1772  * @brief Formats AccountModified message into JSON
1773  *
1774  * See header file for more information
1775  * @endinternal
1776  */
1777 nlohmann::json accountModified()
1778 {
1779     return getLog(redfish::registries::base::Index::accountModified, {});
1780 }
1781 
1782 void accountModified(crow::Response& res)
1783 {
1784     res.result(boost::beast::http::status::ok);
1785     addMessageToErrorJson(res.jsonValue, accountModified());
1786 }
1787 
1788 /**
1789  * @internal
1790  * @brief Formats QueryParameterOutOfRange message into JSON
1791  *
1792  * See header file for more information
1793  * @endinternal
1794  */
1795 nlohmann::json queryParameterOutOfRange(
1796     std::string_view arg1, std::string_view arg2, std::string_view arg3)
1797 {
1798     return getLog(redfish::registries::base::Index::queryParameterOutOfRange,
1799                   std::to_array({arg1, arg2, arg3}));
1800 }
1801 
1802 void queryParameterOutOfRange(crow::Response& res, std::string_view arg1,
1803                               std::string_view arg2, std::string_view arg3)
1804 {
1805     res.result(boost::beast::http::status::bad_request);
1806     addMessageToErrorJson(res.jsonValue,
1807                           queryParameterOutOfRange(arg1, arg2, arg3));
1808 }
1809 
1810 nlohmann::json passwordChangeRequired(const boost::urls::url_view_base& arg1)
1811 {
1812     return getLog(redfish::registries::base::Index::passwordChangeRequired,
1813                   std::to_array<std::string_view>({arg1.buffer()}));
1814 }
1815 
1816 /**
1817  * @internal
1818  * @brief Formats PasswordChangeRequired message into JSON
1819  *
1820  * See header file for more information
1821  * @endinternal
1822  */
1823 void passwordChangeRequired(crow::Response& res,
1824                             const boost::urls::url_view_base& arg1)
1825 {
1826     messages::addMessageToJsonRoot(res.jsonValue, passwordChangeRequired(arg1));
1827 }
1828 
1829 /**
1830  * @internal
1831  * @brief Formats InsufficientStorage message into JSON
1832  *
1833  * See header file for more information
1834  * @endinternal
1835  */
1836 nlohmann::json insufficientStorage()
1837 {
1838     return getLog(redfish::registries::base::Index::insufficientStorage, {});
1839 }
1840 
1841 void insufficientStorage(crow::Response& res)
1842 {
1843     res.result(boost::beast::http::status::insufficient_storage);
1844     addMessageToErrorJson(res.jsonValue, insufficientStorage());
1845 }
1846 
1847 /**
1848  * @internal
1849  * @brief Formats OperationNotAllowed message into JSON
1850  *
1851  * See header file for more information
1852  * @endinternal
1853  */
1854 nlohmann::json operationNotAllowed()
1855 {
1856     return getLog(redfish::registries::base::Index::operationNotAllowed, {});
1857 }
1858 
1859 void operationNotAllowed(crow::Response& res)
1860 {
1861     res.result(boost::beast::http::status::method_not_allowed);
1862     addMessageToErrorJson(res.jsonValue, operationNotAllowed());
1863 }
1864 
1865 /**
1866  * @internal
1867  * @brief Formats ArraySizeTooLong message into JSON
1868  *
1869  * See header file for more information
1870  * @endinternal
1871  */
1872 nlohmann::json arraySizeTooLong(std::string_view property, uint64_t length)
1873 {
1874     std::string valStr = std::to_string(length);
1875     return getLog(redfish::registries::base::Index::arraySizeTooLong,
1876                   std::to_array<std::string_view>({property, valStr}));
1877 }
1878 
1879 void arraySizeTooLong(crow::Response& res, std::string_view property,
1880                       uint64_t length)
1881 {
1882     res.result(boost::beast::http::status::bad_request);
1883     addMessageToErrorJson(res.jsonValue, arraySizeTooLong(property, length));
1884 }
1885 
1886 void invalidUpload(crow::Response& res, std::string_view arg1,
1887                    std::string_view arg2)
1888 {
1889     res.result(boost::beast::http::status::bad_request);
1890     addMessageToErrorJson(res.jsonValue, invalidUpload(arg1, arg2));
1891 }
1892 
1893 /**
1894  * @internal
1895  * @brief Formats Invalid File message into JSON
1896  *
1897  * See header file for more information
1898  * @endinternal
1899  */
1900 nlohmann::json invalidUpload(std::string_view arg1, std::string_view arg2)
1901 {
1902     std::string msg = "Invalid file uploaded to ";
1903     msg += arg1;
1904     msg += ": ";
1905     msg += arg2;
1906     msg += ".";
1907 
1908     nlohmann::json::object_t ret;
1909     ret["@odata.type"] = "/redfish/v1/$metadata#Message.v1_1_1.Message";
1910     ret["MessageId"] = "OpenBMC.0.2.InvalidUpload";
1911     ret["Message"] = std::move(msg);
1912     nlohmann::json::array_t args;
1913     args.emplace_back(arg1);
1914     args.emplace_back(arg2);
1915     ret["MessageArgs"] = std::move(args);
1916     ret["MessageSeverity"] = "Warning";
1917     ret["Resolution"] = "None.";
1918     return ret;
1919 }
1920 
1921 } // namespace messages
1922 
1923 } // namespace redfish
1924