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.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(boost::urls::url_view 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, boost::urls::url_view arg1)
216 {
217     res.result(boost::beast::http::status::bad_request);
218     addMessageToErrorJson(res.jsonValue, resourceMissingAtURI(arg1));
219 }
220 
221 /**
222  * @internal
223  * @brief Formats ActionParameterValueFormatError message into JSON
224  *
225  * See header file for more information
226  * @endinternal
227  */
228 nlohmann::json actionParameterValueFormatError(const nlohmann::json& arg1,
229                                                std::string_view arg2,
230                                                std::string_view arg3)
231 {
232     std::string arg1Str = arg1.dump(2, ' ', true,
233                                     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(crow::Response& res,
240                                      const nlohmann::json& arg1,
241                                      std::string_view arg2,
242                                      std::string_view arg3)
243 {
244     res.result(boost::beast::http::status::bad_request);
245     addMessageToErrorJson(res.jsonValue,
246                           actionParameterValueFormatError(arg1, arg2, arg3));
247 }
248 
249 /**
250  * @internal
251  * @brief Formats ActionParameterValueNotInList message into JSON
252  *
253  * See header file for more information
254  * @endinternal
255  */
256 nlohmann::json actionParameterValueNotInList(std::string_view arg1,
257                                              std::string_view arg2,
258                                              std::string_view arg3)
259 {
260     return getLog(
261         redfish::registries::base::Index::actionParameterValueNotInList,
262         std::to_array({arg1, arg2, arg3}));
263 }
264 
265 void actionParameterValueNotInList(crow::Response& res, std::string_view arg1,
266                                    std::string_view arg2, std::string_view arg3)
267 {
268     res.result(boost::beast::http::status::bad_request);
269     addMessageToErrorJson(res.jsonValue,
270                           actionParameterValueNotInList(arg1, arg2, arg3));
271 }
272 
273 /**
274  * @internal
275  * @brief Formats InternalError message into JSON
276  *
277  * See header file for more information
278  * @endinternal
279  */
280 nlohmann::json internalError()
281 {
282     return getLog(redfish::registries::base::Index::internalError, {});
283 }
284 
285 void internalError(crow::Response& res, const std::source_location location)
286 {
287     BMCWEB_LOG_CRITICAL("Internal Error {}({}:{}) `{}`: ", location.file_name(),
288                         location.line(), location.column(),
289                         location.function_name());
290     res.result(boost::beast::http::status::internal_server_error);
291     addMessageToErrorJson(res.jsonValue, internalError());
292 }
293 
294 /**
295  * @internal
296  * @brief Formats UnrecognizedRequestBody message into JSON
297  *
298  * See header file for more information
299  * @endinternal
300  */
301 nlohmann::json unrecognizedRequestBody()
302 {
303     return getLog(redfish::registries::base::Index::unrecognizedRequestBody,
304                   {});
305 }
306 
307 void unrecognizedRequestBody(crow::Response& res)
308 {
309     res.result(boost::beast::http::status::bad_request);
310     addMessageToErrorJson(res.jsonValue, unrecognizedRequestBody());
311 }
312 
313 /**
314  * @internal
315  * @brief Formats ResourceAtUriUnauthorized message into JSON
316  *
317  * See header file for more information
318  * @endinternal
319  */
320 nlohmann::json resourceAtUriUnauthorized(boost::urls::url_view arg1,
321                                          std::string_view arg2)
322 {
323     return getLog(redfish::registries::base::Index::resourceAtUriUnauthorized,
324                   std::to_array<std::string_view>({arg1.buffer(), arg2}));
325 }
326 
327 void resourceAtUriUnauthorized(crow::Response& res, boost::urls::url_view arg1,
328                                std::string_view arg2)
329 {
330     res.result(boost::beast::http::status::unauthorized);
331     addMessageToErrorJson(res.jsonValue, resourceAtUriUnauthorized(arg1, arg2));
332 }
333 
334 /**
335  * @internal
336  * @brief Formats ActionParameterUnknown message into JSON
337  *
338  * See header file for more information
339  * @endinternal
340  */
341 nlohmann::json actionParameterUnknown(std::string_view arg1,
342                                       std::string_view arg2)
343 {
344     return getLog(redfish::registries::base::Index::actionParameterUnknown,
345                   std::to_array({arg1, arg2}));
346 }
347 
348 void actionParameterUnknown(crow::Response& res, std::string_view arg1,
349                             std::string_view arg2)
350 {
351     res.result(boost::beast::http::status::bad_request);
352     addMessageToErrorJson(res.jsonValue, actionParameterUnknown(arg1, arg2));
353 }
354 
355 /**
356  * @internal
357  * @brief Formats ResourceCannotBeDeleted message into JSON
358  *
359  * See header file for more information
360  * @endinternal
361  */
362 nlohmann::json resourceCannotBeDeleted()
363 {
364     return getLog(redfish::registries::base::Index::resourceCannotBeDeleted,
365                   {});
366 }
367 
368 void resourceCannotBeDeleted(crow::Response& res)
369 {
370     res.result(boost::beast::http::status::method_not_allowed);
371     addMessageToErrorJson(res.jsonValue, resourceCannotBeDeleted());
372 }
373 
374 /**
375  * @internal
376  * @brief Formats PropertyDuplicate message into JSON
377  *
378  * See header file for more information
379  * @endinternal
380  */
381 nlohmann::json propertyDuplicate(std::string_view arg1)
382 {
383     return getLog(redfish::registries::base::Index::propertyDuplicate,
384                   std::to_array({arg1}));
385 }
386 
387 void propertyDuplicate(crow::Response& res, std::string_view arg1)
388 {
389     res.result(boost::beast::http::status::bad_request);
390     addMessageToJson(res.jsonValue, propertyDuplicate(arg1), arg1);
391 }
392 
393 /**
394  * @internal
395  * @brief Formats ServiceTemporarilyUnavailable message into JSON
396  *
397  * See header file for more information
398  * @endinternal
399  */
400 nlohmann::json serviceTemporarilyUnavailable(std::string_view arg1)
401 {
402     return getLog(
403         redfish::registries::base::Index::serviceTemporarilyUnavailable,
404         std::to_array({arg1}));
405 }
406 
407 void serviceTemporarilyUnavailable(crow::Response& res, std::string_view arg1)
408 {
409     res.addHeader(boost::beast::http::field::retry_after, arg1);
410     res.result(boost::beast::http::status::service_unavailable);
411     addMessageToErrorJson(res.jsonValue, serviceTemporarilyUnavailable(arg1));
412 }
413 
414 /**
415  * @internal
416  * @brief Formats ResourceAlreadyExists message into JSON
417  *
418  * See header file for more information
419  * @endinternal
420  */
421 nlohmann::json resourceAlreadyExists(std::string_view arg1,
422                                      std::string_view arg2,
423                                      std::string_view arg3)
424 {
425     return getLog(redfish::registries::base::Index::resourceAlreadyExists,
426                   std::to_array({arg1, arg2, arg3}));
427 }
428 
429 void resourceAlreadyExists(crow::Response& res, std::string_view arg1,
430                            std::string_view arg2, std::string_view arg3)
431 {
432     res.result(boost::beast::http::status::bad_request);
433     addMessageToJson(res.jsonValue, resourceAlreadyExists(arg1, arg2, arg3),
434                      arg2);
435 }
436 
437 /**
438  * @internal
439  * @brief Formats AccountForSessionNoLongerExists message into JSON
440  *
441  * See header file for more information
442  * @endinternal
443  */
444 nlohmann::json accountForSessionNoLongerExists()
445 {
446     return getLog(
447         redfish::registries::base::Index::accountForSessionNoLongerExists, {});
448 }
449 
450 void accountForSessionNoLongerExists(crow::Response& res)
451 {
452     res.result(boost::beast::http::status::forbidden);
453     addMessageToErrorJson(res.jsonValue, accountForSessionNoLongerExists());
454 }
455 
456 /**
457  * @internal
458  * @brief Formats CreateFailedMissingReqProperties message into JSON
459  *
460  * See header file for more information
461  * @endinternal
462  */
463 nlohmann::json createFailedMissingReqProperties(std::string_view arg1)
464 {
465     return getLog(
466         redfish::registries::base::Index::createFailedMissingReqProperties,
467         std::to_array({arg1}));
468 }
469 
470 void createFailedMissingReqProperties(crow::Response& res,
471                                       std::string_view arg1)
472 {
473     res.result(boost::beast::http::status::bad_request);
474     addMessageToJson(res.jsonValue, createFailedMissingReqProperties(arg1),
475                      arg1);
476 }
477 
478 /**
479  * @internal
480  * @brief Formats PropertyValueFormatError message into JSON for the specified
481  * property
482  *
483  * See header file for more information
484  * @endinternal
485  */
486 nlohmann::json propertyValueFormatError(const nlohmann::json& arg1,
487                                         std::string_view arg2)
488 {
489     std::string arg1Str = arg1.dump(2, ' ', true,
490                                     nlohmann::json::error_handler_t::replace);
491     return getLog(redfish::registries::base::Index::propertyValueFormatError,
492                   std::to_array<std::string_view>({arg1Str, arg2}));
493 }
494 
495 void propertyValueFormatError(crow::Response& res, const nlohmann::json& arg1,
496                               std::string_view arg2)
497 {
498     res.result(boost::beast::http::status::bad_request);
499     addMessageToJson(res.jsonValue, propertyValueFormatError(arg1, arg2), arg2);
500 }
501 
502 /**
503  * @internal
504  * @brief Formats PropertyValueNotInList message into JSON for the specified
505  * property
506  *
507  * See header file for more information
508  * @endinternal
509  */
510 
511 nlohmann::json propertyValueNotInList(const nlohmann::json& arg1,
512                                       std::string_view arg2)
513 {
514     std::string arg1Str = arg1.dump(-1, ' ', true,
515                                     nlohmann::json::error_handler_t::replace);
516     return getLog(redfish::registries::base::Index::propertyValueNotInList,
517                   std::to_array<std::string_view>({arg1Str, arg2}));
518 }
519 
520 void propertyValueNotInList(crow::Response& res, const nlohmann::json& arg1,
521                             std::string_view arg2)
522 {
523     res.result(boost::beast::http::status::bad_request);
524     addMessageToJson(res.jsonValue, propertyValueNotInList(arg1, arg2), arg2);
525 }
526 
527 /**
528  * @internal
529  * @brief Formats PropertyValueOutOfRange message into JSON
530  *
531  * See header file for more information
532  * @endinternal
533  */
534 nlohmann::json propertyValueOutOfRange(const nlohmann::json& arg1,
535                                        std::string_view arg2)
536 {
537     std::string arg1Str = arg1.dump(2, ' ', true,
538                                     nlohmann::json::error_handler_t::replace);
539     return getLog(redfish::registries::base::Index::propertyValueOutOfRange,
540                   std::to_array<std::string_view>({arg1Str, arg2}));
541 }
542 
543 void propertyValueOutOfRange(crow::Response& res, const nlohmann::json& arg1,
544                              std::string_view arg2)
545 {
546     res.result(boost::beast::http::status::bad_request);
547     addMessageToErrorJson(res.jsonValue, propertyValueOutOfRange(arg1, arg2));
548 }
549 
550 /**
551  * @internal
552  * @brief Formats ResourceAtUriInUnknownFormat message into JSON
553  *
554  * See header file for more information
555  * @endinternal
556  */
557 nlohmann::json resourceAtUriInUnknownFormat(boost::urls::url_view arg1)
558 {
559     return getLog(
560         redfish::registries::base::Index::resourceAtUriInUnknownFormat,
561         std::to_array<std::string_view>({arg1.buffer()}));
562 }
563 
564 void resourceAtUriInUnknownFormat(crow::Response& res,
565                                   boost::urls::url_view arg1)
566 {
567     res.result(boost::beast::http::status::bad_request);
568     addMessageToErrorJson(res.jsonValue, resourceAtUriInUnknownFormat(arg1));
569 }
570 
571 /**
572  * @internal
573  * @brief Formats ServiceDisabled message into JSON
574  *
575  * See header file for more information
576  * @endinternal
577  */
578 nlohmann::json serviceDisabled(std::string_view arg1)
579 {
580     return getLog(redfish::registries::base::Index::serviceDisabled,
581                   std::to_array({arg1}));
582 }
583 
584 void serviceDisabled(crow::Response& res, std::string_view arg1)
585 {
586     res.result(boost::beast::http::status::service_unavailable);
587     addMessageToErrorJson(res.jsonValue, serviceDisabled(arg1));
588 }
589 
590 /**
591  * @internal
592  * @brief Formats ServiceInUnknownState message into JSON
593  *
594  * See header file for more information
595  * @endinternal
596  */
597 nlohmann::json serviceInUnknownState()
598 {
599     return getLog(redfish::registries::base::Index::serviceInUnknownState, {});
600 }
601 
602 void serviceInUnknownState(crow::Response& res)
603 {
604     res.result(boost::beast::http::status::service_unavailable);
605     addMessageToErrorJson(res.jsonValue, serviceInUnknownState());
606 }
607 
608 /**
609  * @internal
610  * @brief Formats EventSubscriptionLimitExceeded message into JSON
611  *
612  * See header file for more information
613  * @endinternal
614  */
615 nlohmann::json eventSubscriptionLimitExceeded()
616 {
617     return getLog(
618         redfish::registries::base::Index::eventSubscriptionLimitExceeded, {});
619 }
620 
621 void eventSubscriptionLimitExceeded(crow::Response& res)
622 {
623     res.result(boost::beast::http::status::service_unavailable);
624     addMessageToErrorJson(res.jsonValue, eventSubscriptionLimitExceeded());
625 }
626 
627 /**
628  * @internal
629  * @brief Formats ActionParameterMissing message into JSON
630  *
631  * See header file for more information
632  * @endinternal
633  */
634 nlohmann::json actionParameterMissing(std::string_view arg1,
635                                       std::string_view arg2)
636 {
637     return getLog(redfish::registries::base::Index::actionParameterMissing,
638                   std::to_array({arg1, arg2}));
639 }
640 
641 void actionParameterMissing(crow::Response& res, std::string_view arg1,
642                             std::string_view arg2)
643 {
644     res.result(boost::beast::http::status::bad_request);
645     addMessageToErrorJson(res.jsonValue, actionParameterMissing(arg1, arg2));
646 }
647 
648 /**
649  * @internal
650  * @brief Formats StringValueTooLong message into JSON
651  *
652  * See header file for more information
653  * @endinternal
654  */
655 nlohmann::json stringValueTooLong(std::string_view arg1, int arg2)
656 {
657     std::string arg2String = std::to_string(arg2);
658     return getLog(redfish::registries::base::Index::stringValueTooLong,
659                   std::to_array({arg1, std::string_view(arg2String)}));
660 }
661 
662 void stringValueTooLong(crow::Response& res, std::string_view arg1, int arg2)
663 {
664     res.result(boost::beast::http::status::bad_request);
665     addMessageToErrorJson(res.jsonValue, stringValueTooLong(arg1, arg2));
666 }
667 
668 /**
669  * @internal
670  * @brief Formats SessionTerminated message into JSON
671  *
672  * See header file for more information
673  * @endinternal
674  */
675 nlohmann::json sessionTerminated()
676 {
677     return getLog(redfish::registries::base::Index::sessionTerminated, {});
678 }
679 
680 void sessionTerminated(crow::Response& res)
681 {
682     res.result(boost::beast::http::status::ok);
683     addMessageToJsonRoot(res.jsonValue, sessionTerminated());
684 }
685 
686 /**
687  * @internal
688  * @brief Formats SubscriptionTerminated message into JSON
689  *
690  * See header file for more information
691  * @endinternal
692  */
693 nlohmann::json subscriptionTerminated()
694 {
695     return getLog(redfish::registries::base::Index::subscriptionTerminated, {});
696 }
697 
698 void subscriptionTerminated(crow::Response& res)
699 {
700     res.result(boost::beast::http::status::ok);
701     addMessageToJsonRoot(res.jsonValue, subscriptionTerminated());
702 }
703 
704 /**
705  * @internal
706  * @brief Formats ResourceTypeIncompatible message into JSON
707  *
708  * See header file for more information
709  * @endinternal
710  */
711 nlohmann::json resourceTypeIncompatible(std::string_view arg1,
712                                         std::string_view arg2)
713 {
714     return getLog(redfish::registries::base::Index::resourceTypeIncompatible,
715                   std::to_array({arg1, arg2}));
716 }
717 
718 void resourceTypeIncompatible(crow::Response& res, std::string_view arg1,
719                               std::string_view arg2)
720 {
721     res.result(boost::beast::http::status::bad_request);
722     addMessageToErrorJson(res.jsonValue, resourceTypeIncompatible(arg1, arg2));
723 }
724 
725 /**
726  * @internal
727  * @brief Formats ResetRequired message into JSON
728  *
729  * See header file for more information
730  * @endinternal
731  */
732 nlohmann::json resetRequired(boost::urls::url_view arg1, 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, boost::urls::url_view 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(std::string_view arg1,
813                                              const nlohmann::json& arg2,
814                                              boost::urls::url_view arg3)
815 {
816     std::string arg2Str = arg2.dump(2, ' ', true,
817                                     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                                    boost::urls::url_view 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 = arg2.dump(2, ' ', true,
844                                     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 = arg2.dump(2, ' ', true,
870                                     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(boost::urls::url_view 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, boost::urls::url_view arg1)
896 {
897     res.result(boost::beast::http::status::bad_request);
898     addMessageToErrorJson(res.jsonValue, resourceCreationConflict(arg1));
899 }
900 
901 /**
902  * @internal
903  * @brief Formats MaximumErrorsExceeded message into JSON
904  *
905  * See header file for more information
906  * @endinternal
907  */
908 nlohmann::json maximumErrorsExceeded()
909 {
910     return getLog(redfish::registries::base::Index::maximumErrorsExceeded, {});
911 }
912 
913 void maximumErrorsExceeded(crow::Response& res)
914 {
915     res.result(boost::beast::http::status::internal_server_error);
916     addMessageToErrorJson(res.jsonValue, maximumErrorsExceeded());
917 }
918 
919 /**
920  * @internal
921  * @brief Formats PreconditionFailed message into JSON
922  *
923  * See header file for more information
924  * @endinternal
925  */
926 nlohmann::json preconditionFailed()
927 {
928     return getLog(redfish::registries::base::Index::preconditionFailed, {});
929 }
930 
931 void preconditionFailed(crow::Response& res)
932 {
933     res.result(boost::beast::http::status::precondition_failed);
934     addMessageToErrorJson(res.jsonValue, preconditionFailed());
935 }
936 
937 /**
938  * @internal
939  * @brief Formats PreconditionRequired message into JSON
940  *
941  * See header file for more information
942  * @endinternal
943  */
944 nlohmann::json preconditionRequired()
945 {
946     return getLog(redfish::registries::base::Index::preconditionRequired, {});
947 }
948 
949 void preconditionRequired(crow::Response& res)
950 {
951     res.result(boost::beast::http::status::bad_request);
952     addMessageToErrorJson(res.jsonValue, preconditionRequired());
953 }
954 
955 /**
956  * @internal
957  * @brief Formats OperationFailed message into JSON
958  *
959  * See header file for more information
960  * @endinternal
961  */
962 nlohmann::json operationFailed()
963 {
964     return getLog(redfish::registries::base::Index::operationFailed, {});
965 }
966 
967 void operationFailed(crow::Response& res)
968 {
969     res.result(boost::beast::http::status::bad_gateway);
970     addMessageToErrorJson(res.jsonValue, operationFailed());
971 }
972 
973 /**
974  * @internal
975  * @brief Formats OperationTimeout message into JSON
976  *
977  * See header file for more information
978  * @endinternal
979  */
980 nlohmann::json operationTimeout()
981 {
982     return getLog(redfish::registries::base::Index::operationTimeout, {});
983 }
984 
985 void operationTimeout(crow::Response& res)
986 {
987     res.result(boost::beast::http::status::internal_server_error);
988     addMessageToErrorJson(res.jsonValue, operationTimeout());
989 }
990 
991 /**
992  * @internal
993  * @brief Formats PropertyValueTypeError message into JSON for the specified
994  * property
995  *
996  * See header file for more information
997  * @endinternal
998  */
999 nlohmann::json propertyValueTypeError(const nlohmann::json& arg1,
1000                                       std::string_view arg2)
1001 {
1002     std::string arg1Str = arg1.dump(2, ' ', true,
1003                                     nlohmann::json::error_handler_t::replace);
1004     return getLog(redfish::registries::base::Index::propertyValueTypeError,
1005                   std::to_array<std::string_view>({arg1Str, arg2}));
1006 }
1007 
1008 void propertyValueTypeError(crow::Response& res, const nlohmann::json& arg1,
1009                             std::string_view arg2)
1010 {
1011     res.result(boost::beast::http::status::bad_request);
1012     addMessageToJson(res.jsonValue, propertyValueTypeError(arg1, arg2), arg2);
1013 }
1014 
1015 /**
1016  * @internal
1017  * @brief Formats ResourceNotFound message into JSONd
1018  *
1019  * See header file for more information
1020  * @endinternal
1021  */
1022 nlohmann::json resourceNotFound(std::string_view arg1, std::string_view arg2)
1023 {
1024     return getLog(redfish::registries::base::Index::resourceNotFound,
1025                   std::to_array({arg1, arg2}));
1026 }
1027 
1028 void resourceNotFound(crow::Response& res, std::string_view arg1,
1029                       std::string_view arg2)
1030 {
1031     res.result(boost::beast::http::status::not_found);
1032     addMessageToErrorJson(res.jsonValue, resourceNotFound(arg1, arg2));
1033 }
1034 
1035 /**
1036  * @internal
1037  * @brief Formats CouldNotEstablishConnection message into JSON
1038  *
1039  * See header file for more information
1040  * @endinternal
1041  */
1042 nlohmann::json couldNotEstablishConnection(boost::urls::url_view arg1)
1043 {
1044     return getLog(redfish::registries::base::Index::couldNotEstablishConnection,
1045                   std::to_array<std::string_view>({arg1.buffer()}));
1046 }
1047 
1048 void couldNotEstablishConnection(crow::Response& res,
1049                                  boost::urls::url_view arg1)
1050 {
1051     res.result(boost::beast::http::status::not_found);
1052     addMessageToErrorJson(res.jsonValue, couldNotEstablishConnection(arg1));
1053 }
1054 
1055 /**
1056  * @internal
1057  * @brief Formats PropertyNotWritable message into JSON for the specified
1058  * property
1059  *
1060  * See header file for more information
1061  * @endinternal
1062  */
1063 nlohmann::json propertyNotWritable(std::string_view arg1)
1064 {
1065     return getLog(redfish::registries::base::Index::propertyNotWritable,
1066                   std::to_array({arg1}));
1067 }
1068 
1069 void propertyNotWritable(crow::Response& res, std::string_view arg1)
1070 {
1071     res.result(boost::beast::http::status::forbidden);
1072     addMessageToJson(res.jsonValue, propertyNotWritable(arg1), arg1);
1073 }
1074 
1075 /**
1076  * @internal
1077  * @brief Formats QueryParameterValueTypeError message into JSON
1078  *
1079  * See header file for more information
1080  * @endinternal
1081  */
1082 nlohmann::json queryParameterValueTypeError(const nlohmann::json& arg1,
1083                                             std::string_view arg2)
1084 {
1085     std::string arg1Str = arg1.dump(2, ' ', true,
1086                                     nlohmann::json::error_handler_t::replace);
1087     return getLog(
1088         redfish::registries::base::Index::queryParameterValueTypeError,
1089         std::to_array<std::string_view>({arg1Str, arg2}));
1090 }
1091 
1092 void queryParameterValueTypeError(crow::Response& res,
1093                                   const nlohmann::json& arg1,
1094                                   std::string_view arg2)
1095 {
1096     res.result(boost::beast::http::status::bad_request);
1097     addMessageToErrorJson(res.jsonValue,
1098                           queryParameterValueTypeError(arg1, arg2));
1099 }
1100 
1101 /**
1102  * @internal
1103  * @brief Formats ServiceShuttingDown message into JSON
1104  *
1105  * See header file for more information
1106  * @endinternal
1107  */
1108 nlohmann::json serviceShuttingDown()
1109 {
1110     return getLog(redfish::registries::base::Index::serviceShuttingDown, {});
1111 }
1112 
1113 void serviceShuttingDown(crow::Response& res)
1114 {
1115     res.result(boost::beast::http::status::service_unavailable);
1116     addMessageToErrorJson(res.jsonValue, serviceShuttingDown());
1117 }
1118 
1119 /**
1120  * @internal
1121  * @brief Formats ActionParameterDuplicate message into JSON
1122  *
1123  * See header file for more information
1124  * @endinternal
1125  */
1126 nlohmann::json actionParameterDuplicate(std::string_view arg1,
1127                                         std::string_view arg2)
1128 {
1129     return getLog(redfish::registries::base::Index::actionParameterDuplicate,
1130                   std::to_array({arg1, arg2}));
1131 }
1132 
1133 void actionParameterDuplicate(crow::Response& res, std::string_view arg1,
1134                               std::string_view arg2)
1135 {
1136     res.result(boost::beast::http::status::bad_request);
1137     addMessageToErrorJson(res.jsonValue, actionParameterDuplicate(arg1, arg2));
1138 }
1139 
1140 /**
1141  * @internal
1142  * @brief Formats ActionParameterNotSupported message into JSON
1143  *
1144  * See header file for more information
1145  * @endinternal
1146  */
1147 nlohmann::json actionParameterNotSupported(std::string_view arg1,
1148                                            std::string_view arg2)
1149 {
1150     return getLog(redfish::registries::base::Index::actionParameterNotSupported,
1151                   std::to_array({arg1, arg2}));
1152 }
1153 
1154 void actionParameterNotSupported(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,
1159                           actionParameterNotSupported(arg1, arg2));
1160 }
1161 
1162 /**
1163  * @internal
1164  * @brief Formats SourceDoesNotSupportProtocol message into JSON
1165  *
1166  * See header file for more information
1167  * @endinternal
1168  */
1169 nlohmann::json sourceDoesNotSupportProtocol(boost::urls::url_view arg1,
1170                                             std::string_view arg2)
1171 {
1172     return getLog(
1173         redfish::registries::base::Index::sourceDoesNotSupportProtocol,
1174         std::to_array<std::string_view>({arg1.buffer(), arg2}));
1175 }
1176 
1177 void sourceDoesNotSupportProtocol(crow::Response& res,
1178                                   boost::urls::url_view arg1,
1179                                   std::string_view arg2)
1180 {
1181     res.result(boost::beast::http::status::bad_request);
1182     addMessageToErrorJson(res.jsonValue,
1183                           sourceDoesNotSupportProtocol(arg1, arg2));
1184 }
1185 
1186 /**
1187  * @internal
1188  * @brief Formats StrictAccountTypes message into JSON
1189  *
1190  * See header file for more information
1191  * @endinternal
1192  */
1193 nlohmann::json strictAccountTypes(std::string_view arg1)
1194 {
1195     return getLog(redfish::registries::base::Index::strictAccountTypes,
1196                   std::to_array({arg1}));
1197 }
1198 
1199 void strictAccountTypes(crow::Response& res, std::string_view arg1)
1200 {
1201     res.result(boost::beast::http::status::bad_request);
1202     addMessageToErrorJson(res.jsonValue, strictAccountTypes(arg1));
1203 }
1204 
1205 /**
1206  * @internal
1207  * @brief Formats AccountRemoved message into JSON
1208  *
1209  * See header file for more information
1210  * @endinternal
1211  */
1212 nlohmann::json accountRemoved()
1213 {
1214     return getLog(redfish::registries::base::Index::accountRemoved, {});
1215 }
1216 
1217 void accountRemoved(crow::Response& res)
1218 {
1219     res.result(boost::beast::http::status::ok);
1220     addMessageToJsonRoot(res.jsonValue, accountRemoved());
1221 }
1222 
1223 /**
1224  * @internal
1225  * @brief Formats AccessDenied message into JSON
1226  *
1227  * See header file for more information
1228  * @endinternal
1229  */
1230 nlohmann::json accessDenied(boost::urls::url_view arg1)
1231 {
1232     return getLog(redfish::registries::base::Index::accessDenied,
1233                   std::to_array<std::string_view>({arg1.buffer()}));
1234 }
1235 
1236 void accessDenied(crow::Response& res, boost::urls::url_view arg1)
1237 {
1238     res.result(boost::beast::http::status::forbidden);
1239     addMessageToErrorJson(res.jsonValue, accessDenied(arg1));
1240 }
1241 
1242 /**
1243  * @internal
1244  * @brief Formats QueryNotSupported message into JSON
1245  *
1246  * See header file for more information
1247  * @endinternal
1248  */
1249 nlohmann::json queryNotSupported()
1250 {
1251     return getLog(redfish::registries::base::Index::queryNotSupported, {});
1252 }
1253 
1254 void queryNotSupported(crow::Response& res)
1255 {
1256     res.result(boost::beast::http::status::bad_request);
1257     addMessageToErrorJson(res.jsonValue, queryNotSupported());
1258 }
1259 
1260 /**
1261  * @internal
1262  * @brief Formats CreateLimitReachedForResource message into JSON
1263  *
1264  * See header file for more information
1265  * @endinternal
1266  */
1267 nlohmann::json createLimitReachedForResource()
1268 {
1269     return getLog(
1270         redfish::registries::base::Index::createLimitReachedForResource, {});
1271 }
1272 
1273 void createLimitReachedForResource(crow::Response& res)
1274 {
1275     res.result(boost::beast::http::status::bad_request);
1276     addMessageToErrorJson(res.jsonValue, createLimitReachedForResource());
1277 }
1278 
1279 /**
1280  * @internal
1281  * @brief Formats GeneralError message into JSON
1282  *
1283  * See header file for more information
1284  * @endinternal
1285  */
1286 nlohmann::json generalError()
1287 {
1288     return getLog(redfish::registries::base::Index::generalError, {});
1289 }
1290 
1291 void generalError(crow::Response& res)
1292 {
1293     res.result(boost::beast::http::status::internal_server_error);
1294     addMessageToErrorJson(res.jsonValue, generalError());
1295 }
1296 
1297 /**
1298  * @internal
1299  * @brief Formats Success message into JSON
1300  *
1301  * See header file for more information
1302  * @endinternal
1303  */
1304 nlohmann::json success()
1305 {
1306     return getLog(redfish::registries::base::Index::success, {});
1307 }
1308 
1309 void success(crow::Response& res)
1310 {
1311     // don't set res.result here because success is the default and any
1312     // error should overwrite the default
1313     addMessageToJsonRoot(res.jsonValue, success());
1314 }
1315 
1316 /**
1317  * @internal
1318  * @brief Formats Created message into JSON
1319  *
1320  * See header file for more information
1321  * @endinternal
1322  */
1323 nlohmann::json created()
1324 {
1325     return getLog(redfish::registries::base::Index::created, {});
1326 }
1327 
1328 void created(crow::Response& res)
1329 {
1330     res.result(boost::beast::http::status::created);
1331     addMessageToJsonRoot(res.jsonValue, created());
1332 }
1333 
1334 /**
1335  * @internal
1336  * @brief Formats NoOperation message into JSON
1337  *
1338  * See header file for more information
1339  * @endinternal
1340  */
1341 nlohmann::json noOperation()
1342 {
1343     return getLog(redfish::registries::base::Index::noOperation, {});
1344 }
1345 
1346 void noOperation(crow::Response& res)
1347 {
1348     res.result(boost::beast::http::status::bad_request);
1349     addMessageToErrorJson(res.jsonValue, noOperation());
1350 }
1351 
1352 /**
1353  * @internal
1354  * @brief Formats PropertyUnknown message into JSON for the specified
1355  * property
1356  *
1357  * See header file for more information
1358  * @endinternal
1359  */
1360 nlohmann::json propertyUnknown(std::string_view arg1)
1361 {
1362     return getLog(redfish::registries::base::Index::propertyUnknown,
1363                   std::to_array({arg1}));
1364 }
1365 
1366 void propertyUnknown(crow::Response& res, std::string_view arg1)
1367 {
1368     res.result(boost::beast::http::status::bad_request);
1369     addMessageToErrorJson(res.jsonValue, propertyUnknown(arg1));
1370 }
1371 
1372 /**
1373  * @internal
1374  * @brief Formats NoValidSession message into JSON
1375  *
1376  * See header file for more information
1377  * @endinternal
1378  */
1379 nlohmann::json noValidSession()
1380 {
1381     return getLog(redfish::registries::base::Index::noValidSession, {});
1382 }
1383 
1384 void noValidSession(crow::Response& res)
1385 {
1386     res.result(boost::beast::http::status::forbidden);
1387     addMessageToErrorJson(res.jsonValue, noValidSession());
1388 }
1389 
1390 /**
1391  * @internal
1392  * @brief Formats InvalidObject message into JSON
1393  *
1394  * See header file for more information
1395  * @endinternal
1396  */
1397 nlohmann::json invalidObject(boost::urls::url_view arg1)
1398 {
1399     return getLog(redfish::registries::base::Index::invalidObject,
1400                   std::to_array<std::string_view>({arg1.buffer()}));
1401 }
1402 
1403 void invalidObject(crow::Response& res, boost::urls::url_view arg1)
1404 {
1405     res.result(boost::beast::http::status::bad_request);
1406     addMessageToErrorJson(res.jsonValue, invalidObject(arg1));
1407 }
1408 
1409 /**
1410  * @internal
1411  * @brief Formats ResourceInStandby message into JSON
1412  *
1413  * See header file for more information
1414  * @endinternal
1415  */
1416 nlohmann::json resourceInStandby()
1417 {
1418     return getLog(redfish::registries::base::Index::resourceInStandby, {});
1419 }
1420 
1421 void resourceInStandby(crow::Response& res)
1422 {
1423     res.result(boost::beast::http::status::service_unavailable);
1424     addMessageToErrorJson(res.jsonValue, resourceInStandby());
1425 }
1426 
1427 /**
1428  * @internal
1429  * @brief Formats ActionParameterValueTypeError message into JSON
1430  *
1431  * See header file for more information
1432  * @endinternal
1433  */
1434 nlohmann::json actionParameterValueTypeError(const nlohmann::json& arg1,
1435                                              std::string_view arg2,
1436                                              std::string_view arg3)
1437 {
1438     std::string arg1Str = arg1.dump(2, ' ', true,
1439                                     nlohmann::json::error_handler_t::replace);
1440     return getLog(
1441         redfish::registries::base::Index::actionParameterValueTypeError,
1442         std::to_array<std::string_view>({arg1Str, arg2, arg3}));
1443 }
1444 
1445 void actionParameterValueTypeError(crow::Response& res,
1446                                    const nlohmann::json& arg1,
1447                                    std::string_view arg2, std::string_view arg3)
1448 {
1449     res.result(boost::beast::http::status::bad_request);
1450     addMessageToErrorJson(res.jsonValue,
1451                           actionParameterValueTypeError(arg1, arg2, arg3));
1452 }
1453 
1454 /**
1455  * @internal
1456  * @brief Formats actionParameterValueError message into JSON
1457  *
1458  * See header file for more information
1459  * @endinternal
1460  */
1461 nlohmann::json actionParameterValueError(const nlohmann::json& arg1,
1462                                          std::string_view arg2)
1463 {
1464     std::string arg1Str = arg1.dump(2, ' ', true,
1465                                     nlohmann::json::error_handler_t::replace);
1466     return getLog(redfish::registries::base::Index::actionParameterValueError,
1467                   std::to_array<std::string_view>({arg1Str, arg2}));
1468 }
1469 
1470 void actionParameterValueError(crow::Response& res, const nlohmann::json& arg1,
1471                                std::string_view arg2)
1472 {
1473     res.result(boost::beast::http::status::bad_request);
1474     addMessageToErrorJson(res.jsonValue, actionParameterValueError(arg1, arg2));
1475 }
1476 
1477 /**
1478  * @internal
1479  * @brief Formats SessionLimitExceeded message into JSON
1480  *
1481  * See header file for more information
1482  * @endinternal
1483  */
1484 nlohmann::json sessionLimitExceeded()
1485 {
1486     return getLog(redfish::registries::base::Index::sessionLimitExceeded, {});
1487 }
1488 
1489 void sessionLimitExceeded(crow::Response& res)
1490 {
1491     res.result(boost::beast::http::status::service_unavailable);
1492     addMessageToErrorJson(res.jsonValue, sessionLimitExceeded());
1493 }
1494 
1495 /**
1496  * @internal
1497  * @brief Formats ActionNotSupported message into JSON
1498  *
1499  * See header file for more information
1500  * @endinternal
1501  */
1502 nlohmann::json actionNotSupported(std::string_view arg1)
1503 {
1504     return getLog(redfish::registries::base::Index::actionNotSupported,
1505                   std::to_array({arg1}));
1506 }
1507 
1508 void actionNotSupported(crow::Response& res, std::string_view arg1)
1509 {
1510     res.result(boost::beast::http::status::bad_request);
1511     addMessageToErrorJson(res.jsonValue, actionNotSupported(arg1));
1512 }
1513 
1514 /**
1515  * @internal
1516  * @brief Formats InvalidIndex message into JSON
1517  *
1518  * See header file for more information
1519  * @endinternal
1520  */
1521 nlohmann::json invalidIndex(int64_t arg1)
1522 {
1523     std::string arg1Str = std::to_string(arg1);
1524     return getLog(redfish::registries::base::Index::invalidIndex,
1525                   std::to_array<std::string_view>({arg1Str}));
1526 }
1527 
1528 void invalidIndex(crow::Response& res, int64_t arg1)
1529 {
1530     res.result(boost::beast::http::status::bad_request);
1531     addMessageToErrorJson(res.jsonValue, invalidIndex(arg1));
1532 }
1533 
1534 /**
1535  * @internal
1536  * @brief Formats EmptyJSON message into JSON
1537  *
1538  * See header file for more information
1539  * @endinternal
1540  */
1541 nlohmann::json emptyJSON()
1542 {
1543     return getLog(redfish::registries::base::Index::emptyJSON, {});
1544 }
1545 
1546 void emptyJSON(crow::Response& res)
1547 {
1548     res.result(boost::beast::http::status::bad_request);
1549     addMessageToErrorJson(res.jsonValue, emptyJSON());
1550 }
1551 
1552 /**
1553  * @internal
1554  * @brief Formats QueryNotSupportedOnResource message into JSON
1555  *
1556  * See header file for more information
1557  * @endinternal
1558  */
1559 nlohmann::json queryNotSupportedOnResource()
1560 {
1561     return getLog(redfish::registries::base::Index::queryNotSupportedOnResource,
1562                   {});
1563 }
1564 
1565 void queryNotSupportedOnResource(crow::Response& res)
1566 {
1567     res.result(boost::beast::http::status::bad_request);
1568     addMessageToErrorJson(res.jsonValue, queryNotSupportedOnResource());
1569 }
1570 
1571 /**
1572  * @internal
1573  * @brief Formats QueryNotSupportedOnOperation message into JSON
1574  *
1575  * See header file for more information
1576  * @endinternal
1577  */
1578 nlohmann::json queryNotSupportedOnOperation()
1579 {
1580     return getLog(
1581         redfish::registries::base::Index::queryNotSupportedOnOperation, {});
1582 }
1583 
1584 void queryNotSupportedOnOperation(crow::Response& res)
1585 {
1586     res.result(boost::beast::http::status::bad_request);
1587     addMessageToErrorJson(res.jsonValue, queryNotSupportedOnOperation());
1588 }
1589 
1590 /**
1591  * @internal
1592  * @brief Formats QueryCombinationInvalid message into JSON
1593  *
1594  * See header file for more information
1595  * @endinternal
1596  */
1597 nlohmann::json queryCombinationInvalid()
1598 {
1599     return getLog(redfish::registries::base::Index::queryCombinationInvalid,
1600                   {});
1601 }
1602 
1603 void queryCombinationInvalid(crow::Response& res)
1604 {
1605     res.result(boost::beast::http::status::bad_request);
1606     addMessageToErrorJson(res.jsonValue, queryCombinationInvalid());
1607 }
1608 
1609 /**
1610  * @internal
1611  * @brief Formats InsufficientPrivilege message into JSON
1612  *
1613  * See header file for more information
1614  * @endinternal
1615  */
1616 nlohmann::json insufficientPrivilege()
1617 {
1618     return getLog(redfish::registries::base::Index::insufficientPrivilege, {});
1619 }
1620 
1621 void insufficientPrivilege(crow::Response& res)
1622 {
1623     res.result(boost::beast::http::status::forbidden);
1624     addMessageToErrorJson(res.jsonValue, insufficientPrivilege());
1625 }
1626 
1627 /**
1628  * @internal
1629  * @brief Formats PropertyValueModified message into JSON
1630  *
1631  * See header file for more information
1632  * @endinternal
1633  */
1634 nlohmann::json propertyValueModified(std::string_view arg1,
1635                                      const nlohmann::json& arg2)
1636 {
1637     std::string arg2Str = arg2.dump(2, ' ', true,
1638                                     nlohmann::json::error_handler_t::replace);
1639     return getLog(redfish::registries::base::Index::propertyValueModified,
1640                   std::to_array<std::string_view>({arg1, arg2Str}));
1641 }
1642 
1643 void propertyValueModified(crow::Response& res, std::string_view arg1,
1644                            const nlohmann::json& arg2)
1645 {
1646     res.result(boost::beast::http::status::ok);
1647     addMessageToJson(res.jsonValue, propertyValueModified(arg1, arg2), arg1);
1648 }
1649 
1650 /**
1651  * @internal
1652  * @brief Formats AccountNotModified message into JSON
1653  *
1654  * See header file for more information
1655  * @endinternal
1656  */
1657 nlohmann::json accountNotModified()
1658 {
1659     return getLog(redfish::registries::base::Index::accountNotModified, {});
1660 }
1661 
1662 void accountNotModified(crow::Response& res)
1663 {
1664     res.result(boost::beast::http::status::bad_request);
1665     addMessageToErrorJson(res.jsonValue, accountNotModified());
1666 }
1667 
1668 /**
1669  * @internal
1670  * @brief Formats QueryParameterValueFormatError message into JSON
1671  *
1672  * See header file for more information
1673  * @endinternal
1674  */
1675 nlohmann::json queryParameterValueFormatError(const nlohmann::json& arg1,
1676                                               std::string_view arg2)
1677 {
1678     std::string arg1Str = arg1.dump(2, ' ', true,
1679                                     nlohmann::json::error_handler_t::replace);
1680     return getLog(
1681         redfish::registries::base::Index::queryParameterValueFormatError,
1682         std::to_array<std::string_view>({arg1Str, arg2}));
1683 }
1684 
1685 void queryParameterValueFormatError(crow::Response& res,
1686                                     const nlohmann::json& arg1,
1687                                     std::string_view arg2)
1688 {
1689     res.result(boost::beast::http::status::bad_request);
1690     addMessageToErrorJson(res.jsonValue,
1691                           queryParameterValueFormatError(arg1, arg2));
1692 }
1693 
1694 /**
1695  * @internal
1696  * @brief Formats PropertyMissing message into JSON for the specified
1697  * property
1698  *
1699  * See header file for more information
1700  * @endinternal
1701  */
1702 nlohmann::json propertyMissing(std::string_view arg1)
1703 {
1704     return getLog(redfish::registries::base::Index::propertyMissing,
1705                   std::to_array({arg1}));
1706 }
1707 
1708 void propertyMissing(crow::Response& res, std::string_view arg1)
1709 {
1710     res.result(boost::beast::http::status::bad_request);
1711     addMessageToJson(res.jsonValue, propertyMissing(arg1), arg1);
1712 }
1713 
1714 /**
1715  * @internal
1716  * @brief Formats ResourceExhaustion message into JSON
1717  *
1718  * See header file for more information
1719  * @endinternal
1720  */
1721 nlohmann::json resourceExhaustion(std::string_view arg1)
1722 {
1723     return getLog(redfish::registries::base::Index::resourceExhaustion,
1724                   std::to_array({arg1}));
1725 }
1726 
1727 void resourceExhaustion(crow::Response& res, std::string_view arg1)
1728 {
1729     res.result(boost::beast::http::status::service_unavailable);
1730     addMessageToErrorJson(res.jsonValue, resourceExhaustion(arg1));
1731 }
1732 
1733 /**
1734  * @internal
1735  * @brief Formats AccountModified message into JSON
1736  *
1737  * See header file for more information
1738  * @endinternal
1739  */
1740 nlohmann::json accountModified()
1741 {
1742     return getLog(redfish::registries::base::Index::accountModified, {});
1743 }
1744 
1745 void accountModified(crow::Response& res)
1746 {
1747     res.result(boost::beast::http::status::ok);
1748     addMessageToErrorJson(res.jsonValue, accountModified());
1749 }
1750 
1751 /**
1752  * @internal
1753  * @brief Formats QueryParameterOutOfRange message into JSON
1754  *
1755  * See header file for more information
1756  * @endinternal
1757  */
1758 nlohmann::json queryParameterOutOfRange(std::string_view arg1,
1759                                         std::string_view arg2,
1760                                         std::string_view arg3)
1761 {
1762     return getLog(redfish::registries::base::Index::queryParameterOutOfRange,
1763                   std::to_array({arg1, arg2, arg3}));
1764 }
1765 
1766 void queryParameterOutOfRange(crow::Response& res, std::string_view arg1,
1767                               std::string_view arg2, std::string_view arg3)
1768 {
1769     res.result(boost::beast::http::status::bad_request);
1770     addMessageToErrorJson(res.jsonValue,
1771                           queryParameterOutOfRange(arg1, arg2, arg3));
1772 }
1773 
1774 nlohmann::json passwordChangeRequired(boost::urls::url_view arg1)
1775 {
1776     return getLog(redfish::registries::base::Index::passwordChangeRequired,
1777                   std::to_array<std::string_view>({arg1.buffer()}));
1778 }
1779 
1780 /**
1781  * @internal
1782  * @brief Formats PasswordChangeRequired message into JSON
1783  *
1784  * See header file for more information
1785  * @endinternal
1786  */
1787 void passwordChangeRequired(crow::Response& res, boost::urls::url_view arg1)
1788 {
1789     messages::addMessageToJsonRoot(res.jsonValue, passwordChangeRequired(arg1));
1790 }
1791 
1792 /**
1793  * @internal
1794  * @brief Formats InsufficientStorage message into JSON
1795  *
1796  * See header file for more information
1797  * @endinternal
1798  */
1799 nlohmann::json insufficientStorage()
1800 {
1801     return getLog(redfish::registries::base::Index::insufficientStorage, {});
1802 }
1803 
1804 void insufficientStorage(crow::Response& res)
1805 {
1806     res.result(boost::beast::http::status::insufficient_storage);
1807     addMessageToErrorJson(res.jsonValue, insufficientStorage());
1808 }
1809 
1810 /**
1811  * @internal
1812  * @brief Formats OperationNotAllowed message into JSON
1813  *
1814  * See header file for more information
1815  * @endinternal
1816  */
1817 nlohmann::json operationNotAllowed()
1818 {
1819     return getLog(redfish::registries::base::Index::operationNotAllowed, {});
1820 }
1821 
1822 void operationNotAllowed(crow::Response& res)
1823 {
1824     res.result(boost::beast::http::status::method_not_allowed);
1825     addMessageToErrorJson(res.jsonValue, operationNotAllowed());
1826 }
1827 
1828 /**
1829  * @internal
1830  * @brief Formats ArraySizeTooLong message into JSON
1831  *
1832  * See header file for more information
1833  * @endinternal
1834  */
1835 nlohmann::json arraySizeTooLong(std::string_view property, uint64_t length)
1836 {
1837     std::string valStr = std::to_string(length);
1838     return getLog(redfish::registries::base::Index::arraySizeTooLong,
1839                   std::to_array<std::string_view>({property, valStr}));
1840 }
1841 
1842 void arraySizeTooLong(crow::Response& res, std::string_view property,
1843                       uint64_t length)
1844 {
1845     res.result(boost::beast::http::status::bad_request);
1846     addMessageToErrorJson(res.jsonValue, arraySizeTooLong(property, length));
1847 }
1848 
1849 void invalidUpload(crow::Response& res, std::string_view arg1,
1850                    std::string_view arg2)
1851 {
1852     res.result(boost::beast::http::status::bad_request);
1853     addMessageToErrorJson(res.jsonValue, invalidUpload(arg1, arg2));
1854 }
1855 
1856 /**
1857  * @internal
1858  * @brief Formats Invalid File message into JSON
1859  *
1860  * See header file for more information
1861  * @endinternal
1862  */
1863 nlohmann::json invalidUpload(std::string_view arg1, std::string_view arg2)
1864 {
1865     std::string msg = "Invalid file uploaded to ";
1866     msg += arg1;
1867     msg += ": ";
1868     msg += arg2;
1869     msg += ".";
1870 
1871     nlohmann::json::object_t ret;
1872     ret["@odata.type"] = "/redfish/v1/$metadata#Message.v1_1_1.Message";
1873     ret["MessageId"] = "OpenBMC.0.2.InvalidUpload";
1874     ret["Message"] = std::move(msg);
1875     nlohmann::json::array_t args;
1876     args.emplace_back(arg1);
1877     args.emplace_back(arg2);
1878     ret["MessageArgs"] = std::move(args);
1879     ret["MessageSeverity"] = "Warning";
1880     ret["Resolution"] = "None.";
1881     return ret;
1882 }
1883 
1884 } // namespace messages
1885 
1886 } // namespace redfish
1887