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