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 #include <logging.hpp>
18 
19 namespace redfish
20 {
21 
22 namespace messages
23 {
24 
25 static void addMessageToErrorJson(nlohmann::json& target,
26                                   const nlohmann::json& message)
27 {
28     auto& error = target["error"];
29 
30     // If this is the first error message, fill in the information from the
31     // first error message to the top level struct
32     if (!error.is_object())
33     {
34         auto messageIdIterator = message.find("MessageId");
35         if (messageIdIterator == message.end())
36         {
37             BMCWEB_LOG_CRITICAL
38                 << "Attempt to add error message without MessageId";
39             return;
40         }
41 
42         auto messageFieldIterator = message.find("Message");
43         if (messageFieldIterator == message.end())
44         {
45             BMCWEB_LOG_CRITICAL
46                 << "Attempt to add error message without Message";
47             return;
48         }
49         error = {{"code", *messageIdIterator},
50                  {"message", *messageFieldIterator}};
51     }
52     else
53     {
54         // More than 1 error occurred, so the message has to be generic
55         error["code"] = std::string(messageVersionPrefix) + "GeneralError";
56         error["message"] = "A general error has occurred. See Resolution for "
57                            "information on how to resolve the error.";
58     }
59 
60     // This check could technically be done in in the default construction
61     // branch above, but because we need the pointer to the extended info field
62     // anyway, it's more efficient to do it here.
63     auto& extendedInfo = error[messages::messageAnnotation];
64     if (!extendedInfo.is_array())
65     {
66         extendedInfo = nlohmann::json::array();
67     }
68 
69     extendedInfo.push_back(message);
70 }
71 
72 static void addMessageToJsonRoot(nlohmann::json& target,
73                                  const nlohmann::json& message)
74 {
75     if (!target[messages::messageAnnotation].is_array())
76     {
77         // Force object to be an array
78         target[messages::messageAnnotation] = nlohmann::json::array();
79     }
80 
81     target[messages::messageAnnotation].push_back(message);
82 }
83 
84 static void addMessageToJson(nlohmann::json& target,
85                              const nlohmann::json& message,
86                              const std::string& fieldPath)
87 {
88     std::string extendedInfo(fieldPath + messages::messageAnnotation);
89 
90     if (!target[extendedInfo].is_array())
91     {
92         // Force object to be an array
93         target[extendedInfo] = nlohmann::json::array();
94     }
95 
96     // Object exists and it is an array so we can just push in the message
97     target[extendedInfo].push_back(message);
98 }
99 
100 /**
101  * @internal
102  * @brief Formats ResourceInUse message into JSON
103  *
104  * See header file for more information
105  * @endinternal
106  */
107 nlohmann::json resourceInUse(void)
108 {
109     return nlohmann::json{
110         {"@odata.type", "#Message.v1_1_1.Message"},
111         {"MessageId", "Base.1.8.1.ResourceInUse"},
112         {"Message", "The change to the requested resource failed because "
113                     "the resource is in use or in transition."},
114         {"MessageArgs", nlohmann::json::array()},
115         {"MessageSeverity", "Warning"},
116         {"Resolution", "Remove the condition and resubmit the request if "
117                        "the operation failed."}};
118 }
119 
120 void resourceInUse(crow::Response& res)
121 {
122     res.result(boost::beast::http::status::service_unavailable);
123     addMessageToErrorJson(res.jsonValue, resourceInUse());
124 }
125 
126 /**
127  * @internal
128  * @brief Formats MalformedJSON message into JSON
129  *
130  * See header file for more information
131  * @endinternal
132  */
133 nlohmann::json malformedJSON(void)
134 {
135     return nlohmann::json{
136         {"@odata.type", "#Message.v1_1_1.Message"},
137         {"MessageId", "Base.1.8.1.MalformedJSON"},
138         {"Message", "The request body submitted was malformed JSON and "
139                     "could not be parsed by the receiving service."},
140         {"MessageArgs", nlohmann::json::array()},
141         {"MessageSeverity", "Critical"},
142         {"Resolution", "Ensure that the request body is valid JSON and "
143                        "resubmit the request."}};
144 }
145 
146 void malformedJSON(crow::Response& res)
147 {
148     res.result(boost::beast::http::status::bad_request);
149     addMessageToErrorJson(res.jsonValue, malformedJSON());
150 }
151 
152 /**
153  * @internal
154  * @brief Formats ResourceMissingAtURI message into JSON
155  *
156  * See header file for more information
157  * @endinternal
158  */
159 nlohmann::json resourceMissingAtURI(const std::string& arg1)
160 {
161     return nlohmann::json{
162         {"@odata.type", "#Message.v1_1_1.Message"},
163         {"MessageId", "Base.1.8.1.ResourceMissingAtURI"},
164         {"Message", "The resource at the URI " + arg1 + " was not found."},
165         {"MessageArgs", {arg1}},
166         {"MessageSeverity", "Critical"},
167         {"Resolution", "Place a valid resource at the URI or correct the "
168                        "URI and resubmit the request."}};
169 }
170 
171 void resourceMissingAtURI(crow::Response& res, const std::string& arg1)
172 {
173     res.result(boost::beast::http::status::bad_request);
174     addMessageToErrorJson(res.jsonValue, resourceMissingAtURI(arg1));
175 }
176 
177 /**
178  * @internal
179  * @brief Formats ActionParameterValueFormatError message into JSON
180  *
181  * See header file for more information
182  * @endinternal
183  */
184 nlohmann::json actionParameterValueFormatError(const std::string& arg1,
185                                                const std::string& arg2,
186                                                const std::string& arg3)
187 {
188     return nlohmann::json{
189         {"@odata.type", "#Message.v1_1_1.Message"},
190         {"MessageId", "Base.1.8.1.ActionParameterValueFormatError"},
191         {"Message",
192          "The value " + arg1 + " for the parameter " + arg2 +
193              " in the action " + arg3 +
194              " is of a different format than the parameter can accept."},
195         {"MessageArgs", {arg1, arg2, arg3}},
196         {"MessageSeverity", "Warning"},
197         {"Resolution",
198          "Correct the value for the parameter in the request body and "
199          "resubmit the request if the operation failed."}};
200 }
201 
202 void actionParameterValueFormatError(crow::Response& res,
203                                      const std::string& arg1,
204                                      const std::string& arg2,
205                                      const std::string& arg3)
206 {
207     res.result(boost::beast::http::status::bad_request);
208     addMessageToErrorJson(res.jsonValue,
209                           actionParameterValueFormatError(arg1, arg2, arg3));
210 }
211 
212 /**
213  * @internal
214  * @brief Formats InternalError message into JSON
215  *
216  * See header file for more information
217  * @endinternal
218  */
219 nlohmann::json internalError(void)
220 {
221     return nlohmann::json{
222         {"@odata.type", "#Message.v1_1_1.Message"},
223         {"MessageId", "Base.1.8.1.InternalError"},
224         {"Message", "The request failed due to an internal service error.  "
225                     "The service is still operational."},
226         {"MessageArgs", nlohmann::json::array()},
227         {"MessageSeverity", "Critical"},
228         {"Resolution", "Resubmit the request.  If the problem persists, "
229                        "consider resetting the service."}};
230 }
231 
232 void internalError(crow::Response& res)
233 {
234     res.result(boost::beast::http::status::internal_server_error);
235     addMessageToErrorJson(res.jsonValue, internalError());
236 }
237 
238 /**
239  * @internal
240  * @brief Formats UnrecognizedRequestBody message into JSON
241  *
242  * See header file for more information
243  * @endinternal
244  */
245 nlohmann::json unrecognizedRequestBody(void)
246 {
247     return nlohmann::json{
248         {"@odata.type", "#Message.v1_1_1.Message"},
249         {"MessageId", "Base.1.8.1.UnrecognizedRequestBody"},
250         {"Message", "The service detected a malformed request body that it "
251                     "was unable to interpret."},
252         {"MessageArgs", nlohmann::json::array()},
253         {"MessageSeverity", "Warning"},
254         {"Resolution", "Correct the request body and resubmit the request "
255                        "if it failed."}};
256 }
257 
258 void unrecognizedRequestBody(crow::Response& res)
259 {
260     res.result(boost::beast::http::status::bad_request);
261     addMessageToErrorJson(res.jsonValue, unrecognizedRequestBody());
262 }
263 
264 /**
265  * @internal
266  * @brief Formats ResourceAtUriUnauthorized message into JSON
267  *
268  * See header file for more information
269  * @endinternal
270  */
271 nlohmann::json resourceAtUriUnauthorized(const std::string& arg1,
272                                          const std::string& arg2)
273 {
274     return nlohmann::json{
275         {"@odata.type", "#Message.v1_1_1.Message"},
276         {"MessageId", "Base.1.8.1.ResourceAtUriUnauthorized"},
277         {"Message", "While accessing the resource at " + arg1 +
278                         ", the service received an authorization error " +
279                         arg2 + "."},
280         {"MessageArgs", {arg1, arg2}},
281         {"MessageSeverity", "Critical"},
282         {"Resolution", "Ensure that the appropriate access is provided for "
283                        "the service in order for it to access the URI."}};
284 }
285 
286 void resourceAtUriUnauthorized(crow::Response& res, const std::string& arg1,
287                                const std::string& arg2)
288 {
289     res.result(boost::beast::http::status::unauthorized);
290     addMessageToErrorJson(res.jsonValue, resourceAtUriUnauthorized(arg1, arg2));
291 }
292 
293 /**
294  * @internal
295  * @brief Formats ActionParameterUnknown message into JSON
296  *
297  * See header file for more information
298  * @endinternal
299  */
300 nlohmann::json actionParameterUnknown(const std::string& arg1,
301                                       const std::string& arg2)
302 {
303     return nlohmann::json{
304         {"@odata.type", "#Message.v1_1_1.Message"},
305         {"MessageId", "Base.1.8.1.ActionParameterUnknown"},
306         {"Message", "The action " + arg1 +
307                         " was submitted with the invalid parameter " + arg2 +
308                         "."},
309         {"MessageArgs", {arg1, arg2}},
310         {"MessageSeverity", "Warning"},
311         {"Resolution", "Correct the invalid parameter and resubmit the "
312                        "request if the operation failed."}};
313 }
314 
315 void actionParameterUnknown(crow::Response& res, const std::string& arg1,
316                             const std::string& arg2)
317 {
318     res.result(boost::beast::http::status::bad_request);
319     addMessageToErrorJson(res.jsonValue, actionParameterUnknown(arg1, arg2));
320 }
321 
322 /**
323  * @internal
324  * @brief Formats ResourceCannotBeDeleted message into JSON
325  *
326  * See header file for more information
327  * @endinternal
328  */
329 nlohmann::json resourceCannotBeDeleted(void)
330 {
331     return nlohmann::json{
332         {"@odata.type", "#Message.v1_1_1.Message"},
333         {"MessageId", "Base.1.8.1.ResourceCannotBeDeleted"},
334         {"Message", "The delete request failed because the resource "
335                     "requested cannot be deleted."},
336         {"MessageArgs", nlohmann::json::array()},
337         {"MessageSeverity", "Critical"},
338         {"Resolution", "Do not attempt to delete a non-deletable resource."}};
339 }
340 
341 void resourceCannotBeDeleted(crow::Response& res)
342 {
343     res.result(boost::beast::http::status::forbidden);
344     addMessageToErrorJson(res.jsonValue, resourceCannotBeDeleted());
345 }
346 
347 /**
348  * @internal
349  * @brief Formats PropertyDuplicate message into JSON
350  *
351  * See header file for more information
352  * @endinternal
353  */
354 nlohmann::json propertyDuplicate(const std::string& arg1)
355 {
356     return nlohmann::json{
357         {"@odata.type", "#Message.v1_1_1.Message"},
358         {"MessageId", "Base.1.8.1.PropertyDuplicate"},
359         {"Message", "The property " + arg1 + " was duplicated in the request."},
360         {"MessageArgs", {arg1}},
361         {"MessageSeverity", "Warning"},
362         {"Resolution",
363          "Remove the duplicate property from the request body and resubmit "
364          "the request if the operation failed."}};
365 }
366 
367 void propertyDuplicate(crow::Response& res, const std::string& arg1)
368 {
369     res.result(boost::beast::http::status::bad_request);
370     addMessageToJson(res.jsonValue, propertyDuplicate(arg1), arg1);
371 }
372 
373 /**
374  * @internal
375  * @brief Formats ServiceTemporarilyUnavailable message into JSON
376  *
377  * See header file for more information
378  * @endinternal
379  */
380 nlohmann::json serviceTemporarilyUnavailable(const std::string& arg1)
381 {
382     return nlohmann::json{
383         {"@odata.type", "#Message.v1_1_1.Message"},
384         {"MessageId", "Base.1.8.1.ServiceTemporarilyUnavailable"},
385         {"Message", "The service is temporarily unavailable.  Retry in " +
386                         arg1 + " seconds."},
387         {"MessageArgs", {arg1}},
388         {"MessageSeverity", "Critical"},
389         {"Resolution", "Wait for the indicated retry duration and retry "
390                        "the operation."}};
391 }
392 
393 void serviceTemporarilyUnavailable(crow::Response& res, const std::string& arg1)
394 {
395     res.addHeader("Retry-After", arg1);
396     res.result(boost::beast::http::status::service_unavailable);
397     addMessageToErrorJson(res.jsonValue, serviceTemporarilyUnavailable(arg1));
398 }
399 
400 /**
401  * @internal
402  * @brief Formats ResourceAlreadyExists message into JSON
403  *
404  * See header file for more information
405  * @endinternal
406  */
407 nlohmann::json resourceAlreadyExists(const std::string& arg1,
408                                      const std::string& arg2,
409                                      const std::string& arg3)
410 {
411     return nlohmann::json{
412         {"@odata.type", "#Message.v1_1_1.Message"},
413         {"MessageId", "Base.1.8.1.ResourceAlreadyExists"},
414         {"Message", "The requested resource of type " + arg1 +
415                         " with the property " + arg2 + " with the value " +
416                         arg3 + " already exists."},
417         {"MessageArgs", {arg1, arg2, arg3}},
418         {"MessageSeverity", "Critical"},
419         {"Resolution", "Do not repeat the create operation as the resource "
420                        "has already been created."}};
421 }
422 
423 void resourceAlreadyExists(crow::Response& res, const std::string& arg1,
424                            const std::string& arg2, const std::string& arg3)
425 {
426     res.result(boost::beast::http::status::bad_request);
427     addMessageToJson(res.jsonValue, resourceAlreadyExists(arg1, arg2, arg3),
428                      arg2);
429 }
430 
431 /**
432  * @internal
433  * @brief Formats AccountForSessionNoLongerExists message into JSON
434  *
435  * See header file for more information
436  * @endinternal
437  */
438 nlohmann::json accountForSessionNoLongerExists(void)
439 {
440     return nlohmann::json{
441         {"@odata.type", "#Message.v1_1_1.Message"},
442         {"MessageId", "Base.1.8.1.AccountForSessionNoLongerExists"},
443         {"Message", "The account for the current session has been removed, "
444                     "thus the current session has been removed as well."},
445         {"MessageArgs", nlohmann::json::array()},
446         {"MessageSeverity", "OK"},
447         {"Resolution", "Attempt to connect with a valid account."}};
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(const std::string& arg1)
464 {
465     return nlohmann::json{
466         {"@odata.type", "#Message.v1_1_1.Message"},
467         {"MessageId", "Base.1.8.1.CreateFailedMissingReqProperties"},
468         {"Message",
469          "The create operation failed because the required property " + arg1 +
470              " was missing from the request."},
471         {"MessageArgs", {arg1}},
472         {"MessageSeverity", "Critical"},
473         {"Resolution",
474          "Correct the body to include the required property with a valid "
475          "value and resubmit the request if the operation failed."}};
476 }
477 
478 void createFailedMissingReqProperties(crow::Response& res,
479                                       const std::string& arg1)
480 {
481     res.result(boost::beast::http::status::bad_request);
482     addMessageToJson(res.jsonValue, createFailedMissingReqProperties(arg1),
483                      arg1);
484 }
485 
486 /**
487  * @internal
488  * @brief Formats PropertyValueFormatError message into JSON for the specified
489  * property
490  *
491  * See header file for more information
492  * @endinternal
493  */
494 nlohmann::json propertyValueFormatError(const std::string& arg1,
495                                         const std::string& arg2)
496 {
497     return nlohmann::json{
498         {"@odata.type", "#Message.v1_1_1.Message"},
499         {"MessageId", "Base.1.8.1.PropertyValueFormatError"},
500         {"Message",
501          "The value " + arg1 + " for the property " + arg2 +
502              " is of a different format than the property can accept."},
503         {"MessageArgs", {arg1, arg2}},
504         {"MessageSeverity", "Warning"},
505         {"Resolution",
506          "Correct the value for the property in the request body and "
507          "resubmit the request if the operation failed."}};
508 }
509 
510 void propertyValueFormatError(crow::Response& res, const std::string& arg1,
511                               const std::string& arg2)
512 {
513     res.result(boost::beast::http::status::bad_request);
514     addMessageToJson(res.jsonValue, propertyValueFormatError(arg1, arg2), arg2);
515 }
516 
517 /**
518  * @internal
519  * @brief Formats PropertyValueNotInList message into JSON for the specified
520  * property
521  *
522  * See header file for more information
523  * @endinternal
524  */
525 nlohmann::json propertyValueNotInList(const std::string& arg1,
526                                       const std::string& arg2)
527 {
528     return nlohmann::json{
529         {"@odata.type", "#Message.v1_1_1.Message"},
530         {"MessageId", "Base.1.8.1.PropertyValueNotInList"},
531         {"Message", "The value " + arg1 + " for the property " + arg2 +
532                         " is not in the list of acceptable values."},
533         {"MessageArgs", {arg1, arg2}},
534         {"MessageSeverity", "Warning"},
535         {"Resolution", "Choose a value from the enumeration list that "
536                        "the implementation "
537                        "can support and resubmit the request if the "
538                        "operation failed."}};
539 }
540 
541 void propertyValueNotInList(crow::Response& res, const std::string& arg1,
542                             const std::string& arg2)
543 {
544     res.result(boost::beast::http::status::bad_request);
545     addMessageToJson(res.jsonValue, propertyValueNotInList(arg1, arg2), 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(const std::string& arg1)
556 {
557     return nlohmann::json{
558         {"@odata.type", "#Message.v1_1_1.Message"},
559         {"MessageId", "Base.1.8.1.ResourceAtUriInUnknownFormat"},
560         {"Message", "The resource at " + arg1 +
561                         " is in a format not recognized by the service."},
562         {"MessageArgs", {arg1}},
563         {"MessageSeverity", "Critical"},
564         {"Resolution", "Place an image or resource or file that is "
565                        "recognized by the service at the URI."}};
566 }
567 
568 void resourceAtUriInUnknownFormat(crow::Response& res, const std::string& arg1)
569 {
570     res.result(boost::beast::http::status::bad_request);
571     addMessageToErrorJson(res.jsonValue, resourceAtUriInUnknownFormat(arg1));
572 }
573 
574 /**
575  * @internal
576  * @brief Formats ServiceDisabled message into JSON
577  *
578  * See header file for more information
579  * @endinternal
580  */
581 nlohmann::json serviceDisabled(const std::string& arg1)
582 {
583     return nlohmann::json{
584         {"@odata.type", "#Message.v1_1_1.Message"},
585         {"MessageId", "Base.1.11.0.ServiceDisabled"},
586         {"Message", "The operation failed because the service at " + arg1 +
587                         " is disabled and cannot accept requests."},
588         {"MessageArgs", {arg1}},
589         {"MessageSeverity", "Warning"},
590         {"Resolution", "Enable the service and resubmit the request if the "
591                        "operation failed."}};
592 }
593 
594 void serviceDisabled(crow::Response& res, const std::string& arg1)
595 {
596     res.result(boost::beast::http::status::service_unavailable);
597     addMessageToErrorJson(res.jsonValue, serviceDisabled(arg1));
598 }
599 
600 /**
601  * @internal
602  * @brief Formats ServiceInUnknownState message into JSON
603  *
604  * See header file for more information
605  * @endinternal
606  */
607 nlohmann::json serviceInUnknownState(void)
608 {
609     return nlohmann::json{
610         {"@odata.type", "#Message.v1_1_1.Message"},
611         {"MessageId", "Base.1.8.1.ServiceInUnknownState"},
612         {"Message",
613          "The operation failed because the service is in an unknown state "
614          "and can no longer take incoming requests."},
615         {"MessageArgs", nlohmann::json::array()},
616         {"MessageSeverity", "Critical"},
617         {"Resolution", "Restart the service and resubmit the request if "
618                        "the operation failed."}};
619 }
620 
621 void serviceInUnknownState(crow::Response& res)
622 {
623     res.result(boost::beast::http::status::service_unavailable);
624     addMessageToErrorJson(res.jsonValue, serviceInUnknownState());
625 }
626 
627 /**
628  * @internal
629  * @brief Formats EventSubscriptionLimitExceeded message into JSON
630  *
631  * See header file for more information
632  * @endinternal
633  */
634 nlohmann::json eventSubscriptionLimitExceeded(void)
635 {
636     return nlohmann::json{
637         {"@odata.type", "#Message.v1_1_1.Message"},
638         {"MessageId", "Base.1.8.1.EventSubscriptionLimitExceeded"},
639         {"Message",
640          "The event subscription failed due to the number of simultaneous "
641          "subscriptions exceeding the limit of the implementation."},
642         {"MessageArgs", nlohmann::json::array()},
643         {"MessageSeverity", "Critical"},
644         {"Resolution",
645          "Reduce the number of other subscriptions before trying to "
646          "establish the event subscription or increase the limit of "
647          "simultaneous subscriptions (if supported)."}};
648 }
649 
650 void eventSubscriptionLimitExceeded(crow::Response& res)
651 {
652     res.result(boost::beast::http::status::service_unavailable);
653     addMessageToErrorJson(res.jsonValue, eventSubscriptionLimitExceeded());
654 }
655 
656 /**
657  * @internal
658  * @brief Formats ActionParameterMissing message into JSON
659  *
660  * See header file for more information
661  * @endinternal
662  */
663 nlohmann::json actionParameterMissing(const std::string& arg1,
664                                       const std::string& arg2)
665 {
666     return nlohmann::json{
667         {"@odata.type", "#Message.v1_1_1.Message"},
668         {"MessageId", "Base.1.8.1.ActionParameterMissing"},
669         {"Message", "The action " + arg1 + " requires the parameter " + arg2 +
670                         " to be present in the request body."},
671         {"MessageArgs", {arg1, arg2}},
672         {"MessageSeverity", "Critical"},
673         {"Resolution",
674          "Supply the action with the required parameter in the request "
675          "body when the request is resubmitted."}};
676 }
677 
678 void actionParameterMissing(crow::Response& res, const std::string& arg1,
679                             const std::string& arg2)
680 {
681     res.result(boost::beast::http::status::bad_request);
682     addMessageToErrorJson(res.jsonValue, actionParameterMissing(arg1, arg2));
683 }
684 
685 /**
686  * @internal
687  * @brief Formats StringValueTooLong message into JSON
688  *
689  * See header file for more information
690  * @endinternal
691  */
692 nlohmann::json stringValueTooLong(const std::string& arg1, const int& arg2)
693 {
694     return nlohmann::json{
695         {"@odata.type", "#Message.v1_1_1.Message"},
696         {"MessageId", "Base.1.8.1.StringValueTooLong"},
697         {"Message", "The string " + arg1 + " exceeds the length limit " +
698                         std::to_string(arg2) + "."},
699         {"MessageArgs", {arg1, std::to_string(arg2)}},
700         {"MessageSeverity", "Warning"},
701         {"Resolution",
702          "Resubmit the request with an appropriate string length."}};
703 }
704 
705 void stringValueTooLong(crow::Response& res, const std::string& arg1,
706                         const int& arg2)
707 {
708     res.result(boost::beast::http::status::bad_request);
709     addMessageToErrorJson(res.jsonValue, stringValueTooLong(arg1, arg2));
710 }
711 
712 /**
713  * @internal
714  * @brief Formats SessionTerminated message into JSON
715  *
716  * See header file for more information
717  * @endinternal
718  */
719 nlohmann::json sessionTerminated(void)
720 {
721     return nlohmann::json{
722         {"@odata.type", "#Message.v1_1_1.Message"},
723         {"MessageId", "Base.1.8.1.SessionTerminated"},
724         {"Message", "The session was successfully terminated."},
725         {"MessageArgs", nlohmann::json::array()},
726         {"MessageSeverity", "OK"},
727         {"Resolution", "No resolution is required."}};
728 }
729 
730 void sessionTerminated(crow::Response& res)
731 {
732     res.result(boost::beast::http::status::ok);
733     addMessageToJsonRoot(res.jsonValue, sessionTerminated());
734 }
735 
736 /**
737  * @internal
738  * @brief Formats SubscriptionTerminated message into JSON
739  *
740  * See header file for more information
741  * @endinternal
742  */
743 nlohmann::json subscriptionTerminated(void)
744 {
745     return nlohmann::json{
746         {"@odata.type", "#Message.v1_1_1.Message"},
747         {"MessageId", "Base.1.8.1.SubscriptionTerminated"},
748         {"Message", "The event subscription has been terminated."},
749         {"MessageArgs", nlohmann::json::array()},
750         {"MessageSeverity", "OK"},
751         {"Resolution", "No resolution is required."}};
752 }
753 
754 void subscriptionTerminated(crow::Response& res)
755 {
756     res.result(boost::beast::http::status::ok);
757     addMessageToJsonRoot(res.jsonValue, subscriptionTerminated());
758 }
759 
760 /**
761  * @internal
762  * @brief Formats ResourceTypeIncompatible message into JSON
763  *
764  * See header file for more information
765  * @endinternal
766  */
767 nlohmann::json resourceTypeIncompatible(const std::string& arg1,
768                                         const std::string& arg2)
769 {
770     return nlohmann::json{
771         {"@odata.type", "#Message.v1_1_1.Message"},
772         {"MessageId", "Base.1.8.1.ResourceTypeIncompatible"},
773         {"Message", "The @odata.type of the request body " + arg1 +
774                         " is incompatible with the @odata.type of the "
775                         "resource which is " +
776                         arg2 + "."},
777         {"MessageArgs", {arg1, arg2}},
778         {"MessageSeverity", "Critical"},
779         {"Resolution", "Resubmit the request with a payload compatible "
780                        "with the resource's schema."}};
781 }
782 
783 void resourceTypeIncompatible(crow::Response& res, const std::string& arg1,
784                               const std::string& arg2)
785 {
786     res.result(boost::beast::http::status::bad_request);
787     addMessageToErrorJson(res.jsonValue, resourceTypeIncompatible(arg1, arg2));
788 }
789 
790 /**
791  * @internal
792  * @brief Formats ResetRequired message into JSON
793  *
794  * See header file for more information
795  * @endinternal
796  */
797 nlohmann::json resetRequired(const std::string& arg1, const std::string& arg2)
798 {
799     return nlohmann::json{
800         {"@odata.type", "#Message.v1_1_1.Message"},
801         {"MessageId", "Base.1.8.1.ResetRequired"},
802         {"Message", "In order to complete the operation, a component reset is "
803                     "required with the Reset action URI '" +
804                         arg1 + "' and ResetType '" + arg2 + "'."},
805         {"MessageArgs", {arg1, arg2}},
806         {"MessageSeverity", "Warning"},
807         {"Resolution",
808          "Perform the required Reset action on the specified component."}};
809 }
810 
811 void resetRequired(crow::Response& res, const std::string& arg1,
812                    const std::string& arg2)
813 {
814     res.result(boost::beast::http::status::bad_request);
815     addMessageToErrorJson(res.jsonValue, resetRequired(arg1, arg2));
816 }
817 
818 /**
819  * @internal
820  * @brief Formats ChassisPowerStateOnRequired message into JSON
821  *
822  * See header file for more information
823  * @endinternal
824  */
825 nlohmann::json chassisPowerStateOnRequired(const std::string& arg1)
826 {
827     return nlohmann::json{
828         {"@odata.type", "#Message.v1_1_1.Message"},
829         {"MessageId", "Base.1.8.1.ChassisPowerStateOnRequired"},
830         {"Message", "The Chassis with Id '" + arg1 +
831                         "' requires to be powered on to perform this request."},
832         {"MessageArgs", {arg1}},
833         {"MessageSeverity", "Warning"},
834         {"Resolution",
835          "Power on the specified Chassis and resubmit the request."}};
836 }
837 
838 void chassisPowerStateOnRequired(crow::Response& res, const std::string& arg1)
839 {
840     res.result(boost::beast::http::status::bad_request);
841     addMessageToErrorJson(res.jsonValue, chassisPowerStateOnRequired(arg1));
842 }
843 
844 /**
845  * @internal
846  * @brief Formats ChassisPowerStateOffRequired message into JSON
847  *
848  * See header file for more information
849  * @endinternal
850  */
851 nlohmann::json chassisPowerStateOffRequired(const std::string& arg1)
852 {
853     return nlohmann::json{
854         {"@odata.type", "#Message.v1_1_1.Message"},
855         {"MessageId", "Base.1.8.1.ChassisPowerStateOffRequired"},
856         {"Message",
857          "The Chassis with Id '" + arg1 +
858              "' requires to be powered off to perform this request."},
859         {"MessageArgs", {arg1}},
860         {"MessageSeverity", "Warning"},
861         {"Resolution",
862          "Power off the specified Chassis and resubmit the request."}};
863 }
864 
865 void chassisPowerStateOffRequired(crow::Response& res, const std::string& arg1)
866 {
867     res.result(boost::beast::http::status::bad_request);
868     addMessageToErrorJson(res.jsonValue, chassisPowerStateOffRequired(arg1));
869 }
870 
871 /**
872  * @internal
873  * @brief Formats PropertyValueConflict message into JSON
874  *
875  * See header file for more information
876  * @endinternal
877  */
878 nlohmann::json propertyValueConflict(const std::string& arg1,
879                                      const std::string& arg2)
880 {
881     return nlohmann::json{
882         {"@odata.type", "#Message.v1_1_1.Message"},
883         {"MessageId", "Base.1.8.1.PropertyValueConflict"},
884         {"Message", "The property '" + arg1 +
885                         "' could not be written because its value would "
886                         "conflict with the value of the '" +
887                         arg2 + "' property."},
888         {"MessageArgs", {arg1, arg2}},
889         {"MessageSeverity", "Warning"},
890         {"Resolution", "No resolution is required."}};
891 }
892 
893 void propertyValueConflict(crow::Response& res, const std::string& arg1,
894                            const std::string& arg2)
895 {
896     res.result(boost::beast::http::status::bad_request);
897     addMessageToErrorJson(res.jsonValue, propertyValueConflict(arg1, arg2));
898 }
899 
900 /**
901  * @internal
902  * @brief Formats PropertyValueIncorrect message into JSON
903  *
904  * See header file for more information
905  * @endinternal
906  */
907 nlohmann::json propertyValueIncorrect(const std::string& arg1,
908                                       const std::string& arg2)
909 {
910     return nlohmann::json{
911         {"@odata.type", "#Message.v1_1_1.Message"},
912         {"MessageId", "Base.1.8.1.PropertyValueIncorrect"},
913         {"Message", "The property '" + arg1 +
914                         "' with the requested value of '" + arg2 +
915                         "' could not be written because the value does not "
916                         "meet the constraints of the implementation."},
917         {"MessageArgs", {arg1, arg2}},
918         {"MessageSeverity", "Warning"},
919         {"Resolution", "No resolution is required."}};
920 }
921 
922 void propertyValueIncorrect(crow::Response& res, const std::string& arg1,
923                             const std::string& arg2)
924 {
925     res.result(boost::beast::http::status::bad_request);
926     addMessageToErrorJson(res.jsonValue, propertyValueIncorrect(arg1, arg2));
927 }
928 
929 /**
930  * @internal
931  * @brief Formats ResourceCreationConflict message into JSON
932  *
933  * See header file for more information
934  * @endinternal
935  */
936 nlohmann::json resourceCreationConflict(const std::string& arg1)
937 {
938     return nlohmann::json{
939         {"@odata.type", "#Message.v1_1_1.Message"},
940         {"MessageId", "Base.1.8.1.ResourceCreationConflict"},
941         {"Message", "The resource could not be created.  The service has a "
942                     "resource at URI '" +
943                         arg1 + "' that conflicts with the creation request."},
944         {"MessageArgs", {arg1}},
945         {"MessageSeverity", "Warning"},
946         {"Resolution", "No resolution is required."}};
947 }
948 
949 void resourceCreationConflict(crow::Response& res, const std::string& arg1)
950 {
951     res.result(boost::beast::http::status::bad_request);
952     addMessageToErrorJson(res.jsonValue, resourceCreationConflict(arg1));
953 }
954 
955 /**
956  * @internal
957  * @brief Formats MaximumErrorsExceeded message into JSON
958  *
959  * See header file for more information
960  * @endinternal
961  */
962 nlohmann::json maximumErrorsExceeded(void)
963 {
964     return nlohmann::json{
965         {"@odata.type", "#Message.v1_1_1.Message"},
966         {"MessageId", "Base.1.8.1.MaximumErrorsExceeded"},
967         {"Message", "Too many errors have occurred to report them all."},
968         {"MessageArgs", nlohmann::json::array()},
969         {"MessageSeverity", "Critical"},
970         {"Resolution",
971          "Resolve other reported errors and retry the current operation."}};
972 }
973 
974 void maximumErrorsExceeded(crow::Response& res)
975 {
976     res.result(boost::beast::http::status::internal_server_error);
977     addMessageToErrorJson(res.jsonValue, maximumErrorsExceeded());
978 }
979 
980 /**
981  * @internal
982  * @brief Formats PreconditionFailed message into JSON
983  *
984  * See header file for more information
985  * @endinternal
986  */
987 nlohmann::json preconditionFailed(void)
988 {
989     return nlohmann::json{
990         {"@odata.type", "#Message.v1_1_1.Message"},
991         {"MessageId", "Base.1.8.1.PreconditionFailed"},
992         {"Message", "The ETag supplied did not match the ETag required to "
993                     "change this resource."},
994         {"MessageArgs", nlohmann::json::array()},
995         {"MessageSeverity", "Critical"},
996         {"Resolution", "Try the operation again using the appropriate ETag."}};
997 }
998 
999 void preconditionFailed(crow::Response& res)
1000 {
1001     res.result(boost::beast::http::status::precondition_failed);
1002     addMessageToErrorJson(res.jsonValue, preconditionFailed());
1003 }
1004 
1005 /**
1006  * @internal
1007  * @brief Formats PreconditionRequired message into JSON
1008  *
1009  * See header file for more information
1010  * @endinternal
1011  */
1012 nlohmann::json preconditionRequired(void)
1013 {
1014     return nlohmann::json{
1015         {"@odata.type", "#Message.v1_1_1.Message"},
1016         {"MessageId", "Base.1.8.1.PreconditionRequired"},
1017         {"Message", "A precondition header or annotation is required to change "
1018                     "this resource."},
1019         {"MessageArgs", nlohmann::json::array()},
1020         {"MessageSeverity", "Critical"},
1021         {"Resolution", "Try the operation again using an If-Match or "
1022                        "If-None-Match header and appropriate ETag."}};
1023 }
1024 
1025 void preconditionRequired(crow::Response& res)
1026 {
1027     res.result(boost::beast::http::status::bad_request);
1028     addMessageToErrorJson(res.jsonValue, preconditionRequired());
1029 }
1030 
1031 /**
1032  * @internal
1033  * @brief Formats OperationFailed message into JSON
1034  *
1035  * See header file for more information
1036  * @endinternal
1037  */
1038 nlohmann::json operationFailed(void)
1039 {
1040     return nlohmann::json{
1041         {"@odata.type", "#Message.v1_1_1.Message"},
1042         {"MessageId", "Base.1.8.1.OperationFailed"},
1043         {"Message",
1044          "An error occurred internal to the service as part of the overall "
1045          "request.  Partial results may have been returned."},
1046         {"MessageArgs", nlohmann::json::array()},
1047         {"MessageSeverity", "Warning"},
1048         {"Resolution", "Resubmit the request.  If the problem persists, "
1049                        "consider resetting the service or provider."}};
1050 }
1051 
1052 void operationFailed(crow::Response& res)
1053 {
1054     res.result(boost::beast::http::status::internal_server_error);
1055     addMessageToErrorJson(res.jsonValue, operationFailed());
1056 }
1057 
1058 /**
1059  * @internal
1060  * @brief Formats OperationTimeout message into JSON
1061  *
1062  * See header file for more information
1063  * @endinternal
1064  */
1065 nlohmann::json operationTimeout(void)
1066 {
1067     return nlohmann::json{
1068         {"@odata.type", "#Message.v1_1_1.Message"},
1069         {"MessageId", "Base.1.8.1.OperationTimeout"},
1070         {"Message", "A timeout internal to the service occured as part of the "
1071                     "request.  Partial results may have been returned."},
1072         {"MessageArgs", nlohmann::json::array()},
1073         {"MessageSeverity", "Warning"},
1074         {"Resolution", "Resubmit the request.  If the problem persists, "
1075                        "consider resetting the service or provider."}};
1076 }
1077 
1078 void operationTimeout(crow::Response& res)
1079 {
1080     res.result(boost::beast::http::status::internal_server_error);
1081     addMessageToErrorJson(res.jsonValue, operationTimeout());
1082 }
1083 
1084 /**
1085  * @internal
1086  * @brief Formats PropertyValueTypeError message into JSON for the specified
1087  * property
1088  *
1089  * See header file for more information
1090  * @endinternal
1091  */
1092 nlohmann::json propertyValueTypeError(const std::string& arg1,
1093                                       const std::string& arg2)
1094 {
1095     return nlohmann::json{
1096         {"@odata.type", "#Message.v1_1_1.Message"},
1097         {"MessageId", "Base.1.8.1.PropertyValueTypeError"},
1098         {"Message",
1099          "The value " + arg1 + " for the property " + arg2 +
1100              " is of a different type than the property can accept."},
1101         {"MessageArgs", {arg1, arg2}},
1102         {"MessageSeverity", "Warning"},
1103         {"Resolution",
1104          "Correct the value for the property in the request body and "
1105          "resubmit the request if the operation failed."}};
1106 }
1107 
1108 void propertyValueTypeError(crow::Response& res, const std::string& arg1,
1109                             const std::string& arg2)
1110 {
1111     res.result(boost::beast::http::status::bad_request);
1112     addMessageToJson(res.jsonValue, propertyValueTypeError(arg1, arg2), arg2);
1113 }
1114 
1115 /**
1116  * @internal
1117  * @brief Formats ResourceNotFound message into JSON
1118  *
1119  * See header file for more information
1120  * @endinternal
1121  */
1122 nlohmann::json resourceNotFound(const std::string& arg1,
1123                                 const std::string& arg2)
1124 {
1125     return nlohmann::json{
1126         {"@odata.type", "#Message.v1_1_1.Message"},
1127         {"MessageId", "Base.1.8.1.ResourceNotFound"},
1128         {"Message", "The requested resource of type " + arg1 + " named " +
1129                         arg2 + " was not found."},
1130         {"MessageArgs", {arg1, arg2}},
1131         {"MessageSeverity", "Critical"},
1132         {"Resolution",
1133          "Provide a valid resource identifier and resubmit the request."}};
1134 }
1135 
1136 void resourceNotFound(crow::Response& res, const std::string& arg1,
1137                       const std::string& arg2)
1138 {
1139     res.result(boost::beast::http::status::not_found);
1140     addMessageToErrorJson(res.jsonValue, resourceNotFound(arg1, arg2));
1141 }
1142 
1143 /**
1144  * @internal
1145  * @brief Formats CouldNotEstablishConnection message into JSON
1146  *
1147  * See header file for more information
1148  * @endinternal
1149  */
1150 nlohmann::json couldNotEstablishConnection(const std::string& arg1)
1151 {
1152     return nlohmann::json{
1153         {"@odata.type", "#Message.v1_1_1.Message"},
1154         {"MessageId", "Base.1.8.1.CouldNotEstablishConnection"},
1155         {"Message",
1156          "The service failed to establish a connection with the URI " + arg1 +
1157              "."},
1158         {"MessageArgs", {arg1}},
1159         {"MessageSeverity", "Critical"},
1160         {"Resolution",
1161          "Ensure that the URI contains a valid and reachable node name, "
1162          "protocol information and other URI components."}};
1163 }
1164 
1165 void couldNotEstablishConnection(crow::Response& res, const std::string& arg1)
1166 {
1167     res.result(boost::beast::http::status::not_found);
1168     addMessageToErrorJson(res.jsonValue, couldNotEstablishConnection(arg1));
1169 }
1170 
1171 /**
1172  * @internal
1173  * @brief Formats PropertyNotWritable message into JSON for the specified
1174  * property
1175  *
1176  * See header file for more information
1177  * @endinternal
1178  */
1179 nlohmann::json propertyNotWritable(const std::string& arg1)
1180 {
1181     return nlohmann::json{
1182         {"@odata.type", "#Message.v1_1_1.Message"},
1183         {"MessageId", "Base.1.8.1.PropertyNotWritable"},
1184         {"Message", "The property " + arg1 +
1185                         " is a read only property and cannot be "
1186                         "assigned a value."},
1187         {"MessageArgs", {arg1}},
1188         {"MessageSeverity", "Warning"},
1189         {"Resolution", "Remove the property from the request body and "
1190                        "resubmit the request if the operation failed."}};
1191 }
1192 
1193 void propertyNotWritable(crow::Response& res, const std::string& arg1)
1194 {
1195     res.result(boost::beast::http::status::forbidden);
1196     addMessageToJson(res.jsonValue, propertyNotWritable(arg1), arg1);
1197 }
1198 
1199 /**
1200  * @internal
1201  * @brief Formats QueryParameterValueTypeError message into JSON
1202  *
1203  * See header file for more information
1204  * @endinternal
1205  */
1206 nlohmann::json queryParameterValueTypeError(const std::string& arg1,
1207                                             const std::string& arg2)
1208 {
1209     return nlohmann::json{
1210         {"@odata.type", "#Message.v1_1_1.Message"},
1211         {"MessageId", "Base.1.8.1.QueryParameterValueTypeError"},
1212         {"Message",
1213          "The value " + arg1 + " for the query parameter " + arg2 +
1214              " is of a different type than the parameter can accept."},
1215         {"MessageArgs", {arg1, arg2}},
1216         {"MessageSeverity", "Warning"},
1217         {"Resolution",
1218          "Correct the value for the query parameter in the request and "
1219          "resubmit the request if the operation failed."}};
1220 }
1221 
1222 void queryParameterValueTypeError(crow::Response& res, const std::string& arg1,
1223                                   const std::string& arg2)
1224 {
1225     res.result(boost::beast::http::status::bad_request);
1226     addMessageToErrorJson(res.jsonValue,
1227                           queryParameterValueTypeError(arg1, arg2));
1228 }
1229 
1230 /**
1231  * @internal
1232  * @brief Formats ServiceShuttingDown message into JSON
1233  *
1234  * See header file for more information
1235  * @endinternal
1236  */
1237 nlohmann::json serviceShuttingDown(void)
1238 {
1239     return nlohmann::json{
1240         {"@odata.type", "#Message.v1_1_1.Message"},
1241         {"MessageId", "Base.1.8.1.ServiceShuttingDown"},
1242         {"Message", "The operation failed because the service is shutting "
1243                     "down and can no longer take incoming requests."},
1244         {"MessageArgs", nlohmann::json::array()},
1245         {"MessageSeverity", "Critical"},
1246         {"Resolution", "When the service becomes available, resubmit the "
1247                        "request if the operation failed."}};
1248 }
1249 
1250 void serviceShuttingDown(crow::Response& res)
1251 {
1252     res.result(boost::beast::http::status::service_unavailable);
1253     addMessageToErrorJson(res.jsonValue, serviceShuttingDown());
1254 }
1255 
1256 /**
1257  * @internal
1258  * @brief Formats ActionParameterDuplicate message into JSON
1259  *
1260  * See header file for more information
1261  * @endinternal
1262  */
1263 nlohmann::json actionParameterDuplicate(const std::string& arg1,
1264                                         const std::string& arg2)
1265 {
1266     return nlohmann::json{
1267         {"@odata.type", "#Message.v1_1_1.Message"},
1268         {"MessageId", "Base.1.8.1.ActionParameterDuplicate"},
1269         {"Message",
1270          "The action " + arg1 +
1271              " was submitted with more than one value for the parameter " +
1272              arg2 + "."},
1273         {"MessageArgs", {arg1, arg2}},
1274         {"MessageSeverity", "Warning"},
1275         {"Resolution",
1276          "Resubmit the action with only one instance of the parameter in "
1277          "the request body if the operation failed."}};
1278 }
1279 
1280 void actionParameterDuplicate(crow::Response& res, const std::string& arg1,
1281                               const std::string& arg2)
1282 {
1283     res.result(boost::beast::http::status::bad_request);
1284     addMessageToErrorJson(res.jsonValue, actionParameterDuplicate(arg1, arg2));
1285 }
1286 
1287 /**
1288  * @internal
1289  * @brief Formats ActionParameterNotSupported message into JSON
1290  *
1291  * See header file for more information
1292  * @endinternal
1293  */
1294 nlohmann::json actionParameterNotSupported(const std::string& arg1,
1295                                            const std::string& arg2)
1296 {
1297     return nlohmann::json{
1298         {"@odata.type", "#Message.v1_1_1.Message"},
1299         {"MessageId", "Base.1.8.1.ActionParameterNotSupported"},
1300         {"Message", "The parameter " + arg1 + " for the action " + arg2 +
1301                         " is not supported on the target resource."},
1302         {"MessageArgs", {arg1, arg2}},
1303         {"MessageSeverity", "Warning"},
1304         {"Resolution", "Remove the parameter supplied and resubmit the "
1305                        "request if the operation failed."}};
1306 }
1307 
1308 void actionParameterNotSupported(crow::Response& res, const std::string& arg1,
1309                                  const std::string& arg2)
1310 {
1311     res.result(boost::beast::http::status::bad_request);
1312     addMessageToErrorJson(res.jsonValue,
1313                           actionParameterNotSupported(arg1, arg2));
1314 }
1315 
1316 /**
1317  * @internal
1318  * @brief Formats SourceDoesNotSupportProtocol message into JSON
1319  *
1320  * See header file for more information
1321  * @endinternal
1322  */
1323 nlohmann::json sourceDoesNotSupportProtocol(const std::string& arg1,
1324                                             const std::string& arg2)
1325 {
1326     return nlohmann::json{
1327         {"@odata.type", "#Message.v1_1_1.Message"},
1328         {"MessageId", "Base.1.8.1.SourceDoesNotSupportProtocol"},
1329         {"Message", "The other end of the connection at " + arg1 +
1330                         " does not support the specified protocol " + arg2 +
1331                         "."},
1332         {"MessageArgs", {arg1, arg2}},
1333         {"MessageSeverity", "Critical"},
1334         {"Resolution", "Change protocols or URIs. "}};
1335 }
1336 
1337 void sourceDoesNotSupportProtocol(crow::Response& res, const std::string& arg1,
1338                                   const std::string& arg2)
1339 {
1340     res.result(boost::beast::http::status::bad_request);
1341     addMessageToErrorJson(res.jsonValue,
1342                           sourceDoesNotSupportProtocol(arg1, arg2));
1343 }
1344 
1345 /**
1346  * @internal
1347  * @brief Formats AccountRemoved message into JSON
1348  *
1349  * See header file for more information
1350  * @endinternal
1351  */
1352 nlohmann::json accountRemoved(void)
1353 {
1354     return nlohmann::json{{"@odata.type", "#Message.v1_1_1.Message"},
1355                           {"MessageId", "Base.1.8.1.AccountRemoved"},
1356                           {"Message", "The account was successfully removed."},
1357                           {"MessageArgs", nlohmann::json::array()},
1358                           {"MessageSeverity", "OK"},
1359                           {"Resolution", "No resolution is required."}};
1360 }
1361 
1362 void accountRemoved(crow::Response& res)
1363 {
1364     res.result(boost::beast::http::status::ok);
1365     addMessageToJsonRoot(res.jsonValue, accountRemoved());
1366 }
1367 
1368 /**
1369  * @internal
1370  * @brief Formats AccessDenied message into JSON
1371  *
1372  * See header file for more information
1373  * @endinternal
1374  */
1375 nlohmann::json accessDenied(const std::string& arg1)
1376 {
1377     return nlohmann::json{
1378         {"@odata.type", "#Message.v1_1_1.Message"},
1379         {"MessageId", "Base.1.8.1.AccessDenied"},
1380         {"Message", "While attempting to establish a connection to " + arg1 +
1381                         ", the service denied access."},
1382         {"MessageArgs", {arg1}},
1383         {"MessageSeverity", "Critical"},
1384         {"Resolution", "Attempt to ensure that the URI is correct and that "
1385                        "the service has the appropriate credentials."}};
1386 }
1387 
1388 void accessDenied(crow::Response& res, const std::string& arg1)
1389 {
1390     res.result(boost::beast::http::status::forbidden);
1391     addMessageToErrorJson(res.jsonValue, accessDenied(arg1));
1392 }
1393 
1394 /**
1395  * @internal
1396  * @brief Formats QueryNotSupported message into JSON
1397  *
1398  * See header file for more information
1399  * @endinternal
1400  */
1401 nlohmann::json queryNotSupported(void)
1402 {
1403     return nlohmann::json{
1404         {"@odata.type", "#Message.v1_1_1.Message"},
1405         {"MessageId", "Base.1.8.1.QueryNotSupported"},
1406         {"Message", "Querying is not supported by the implementation."},
1407         {"MessageArgs", nlohmann::json::array()},
1408         {"MessageSeverity", "Warning"},
1409         {"Resolution", "Remove the query parameters and resubmit the "
1410                        "request if the operation failed."}};
1411 }
1412 
1413 void queryNotSupported(crow::Response& res)
1414 {
1415     res.result(boost::beast::http::status::bad_request);
1416     addMessageToErrorJson(res.jsonValue, queryNotSupported());
1417 }
1418 
1419 /**
1420  * @internal
1421  * @brief Formats CreateLimitReachedForResource message into JSON
1422  *
1423  * See header file for more information
1424  * @endinternal
1425  */
1426 nlohmann::json createLimitReachedForResource(void)
1427 {
1428     return nlohmann::json{
1429         {"@odata.type", "#Message.v1_1_1.Message"},
1430         {"MessageId", "Base.1.8.1.CreateLimitReachedForResource"},
1431         {"Message", "The create operation failed because the resource has "
1432                     "reached the limit of possible resources."},
1433         {"MessageArgs", nlohmann::json::array()},
1434         {"MessageSeverity", "Critical"},
1435         {"Resolution",
1436          "Either delete resources and resubmit the request if the "
1437          "operation failed or do not resubmit the request."}};
1438 }
1439 
1440 void createLimitReachedForResource(crow::Response& res)
1441 {
1442     res.result(boost::beast::http::status::bad_request);
1443     addMessageToErrorJson(res.jsonValue, createLimitReachedForResource());
1444 }
1445 
1446 /**
1447  * @internal
1448  * @brief Formats GeneralError message into JSON
1449  *
1450  * See header file for more information
1451  * @endinternal
1452  */
1453 nlohmann::json generalError(void)
1454 {
1455     return nlohmann::json{{"@odata.type", "#Message.v1_1_1.Message"},
1456                           {"MessageId", "Base.1.8.1.GeneralError"},
1457                           {"Message",
1458                            "A general error has occurred. See Resolution for "
1459                            "information on how to resolve the error."},
1460                           {"MessageArgs", nlohmann::json::array()},
1461                           {"MessageSeverity", "Critical"},
1462                           {"Resolution", "None."}};
1463 }
1464 
1465 void generalError(crow::Response& res)
1466 {
1467     res.result(boost::beast::http::status::internal_server_error);
1468     addMessageToErrorJson(res.jsonValue, generalError());
1469 }
1470 
1471 /**
1472  * @internal
1473  * @brief Formats Success message into JSON
1474  *
1475  * See header file for more information
1476  * @endinternal
1477  */
1478 nlohmann::json success(void)
1479 {
1480     return nlohmann::json{{"@odata.type", "#Message.v1_1_1.Message"},
1481                           {"MessageId", "Base.1.8.1.Success"},
1482                           {"Message", "Successfully Completed Request"},
1483                           {"MessageArgs", nlohmann::json::array()},
1484                           {"MessageSeverity", "OK"},
1485                           {"Resolution", "None"}};
1486 }
1487 
1488 void success(crow::Response& res)
1489 {
1490     // don't set res.result here because success is the default and any
1491     // error should overwrite the default
1492     addMessageToJsonRoot(res.jsonValue, success());
1493 }
1494 
1495 /**
1496  * @internal
1497  * @brief Formats Created message into JSON
1498  *
1499  * See header file for more information
1500  * @endinternal
1501  */
1502 nlohmann::json created(void)
1503 {
1504     return nlohmann::json{
1505         {"@odata.type", "#Message.v1_1_1.Message"},
1506         {"MessageId", "Base.1.8.1.Created"},
1507         {"Message", "The resource has been created successfully"},
1508         {"MessageArgs", nlohmann::json::array()},
1509         {"MessageSeverity", "OK"},
1510         {"Resolution", "None"}};
1511 }
1512 
1513 void created(crow::Response& res)
1514 {
1515     res.result(boost::beast::http::status::created);
1516     addMessageToJsonRoot(res.jsonValue, created());
1517 }
1518 
1519 /**
1520  * @internal
1521  * @brief Formats NoOperation message into JSON
1522  *
1523  * See header file for more information
1524  * @endinternal
1525  */
1526 nlohmann::json noOperation(void)
1527 {
1528     return nlohmann::json{
1529         {"@odata.type", "#Message.v1_1_1.Message"},
1530         {"MessageId", "Base.1.8.1.NoOperation"},
1531         {"Message", "The request body submitted contain no data to act "
1532                     "upon and no changes to the resource took place."},
1533         {"MessageArgs", nlohmann::json::array()},
1534         {"MessageSeverity", "Warning"},
1535         {"Resolution",
1536          "Add properties in the JSON object and resubmit the request."}};
1537 }
1538 
1539 void noOperation(crow::Response& res)
1540 {
1541     res.result(boost::beast::http::status::bad_request);
1542     addMessageToErrorJson(res.jsonValue, noOperation());
1543 }
1544 
1545 /**
1546  * @internal
1547  * @brief Formats PropertyUnknown message into JSON for the specified
1548  * property
1549  *
1550  * See header file for more information
1551  * @endinternal
1552  */
1553 nlohmann::json propertyUnknown(const std::string& arg1)
1554 {
1555     return nlohmann::json{
1556         {"@odata.type", "#Message.v1_1_1.Message"},
1557         {"MessageId", "Base.1.8.1.PropertyUnknown"},
1558         {"Message", "The property " + arg1 +
1559                         " is not in the list of valid properties for "
1560                         "the resource."},
1561         {"MessageArgs", {arg1}},
1562         {"MessageSeverity", "Warning"},
1563         {"Resolution", "Remove the unknown property from the request "
1564                        "body and resubmit "
1565                        "the request if the operation failed."}};
1566 }
1567 
1568 void propertyUnknown(crow::Response& res, const std::string& arg1)
1569 {
1570     res.result(boost::beast::http::status::bad_request);
1571     addMessageToJson(res.jsonValue, propertyUnknown(arg1), arg1);
1572 }
1573 
1574 /**
1575  * @internal
1576  * @brief Formats NoValidSession message into JSON
1577  *
1578  * See header file for more information
1579  * @endinternal
1580  */
1581 nlohmann::json noValidSession(void)
1582 {
1583     return nlohmann::json{
1584         {"@odata.type", "#Message.v1_1_1.Message"},
1585         {"MessageId", "Base.1.8.1.NoValidSession"},
1586         {"Message",
1587          "There is no valid session established with the implementation."},
1588         {"MessageArgs", nlohmann::json::array()},
1589         {"MessageSeverity", "Critical"},
1590         {"Resolution",
1591          "Establish a session before attempting any operations."}};
1592 }
1593 
1594 void noValidSession(crow::Response& res)
1595 {
1596     res.result(boost::beast::http::status::forbidden);
1597     addMessageToErrorJson(res.jsonValue, noValidSession());
1598 }
1599 
1600 /**
1601  * @internal
1602  * @brief Formats InvalidObject message into JSON
1603  *
1604  * See header file for more information
1605  * @endinternal
1606  */
1607 nlohmann::json invalidObject(const std::string& arg1)
1608 {
1609     return nlohmann::json{
1610         {"@odata.type", "#Message.v1_1_1.Message"},
1611         {"MessageId", "Base.1.8.1.InvalidObject"},
1612         {"Message", "The object at " + arg1 + " is invalid."},
1613         {"MessageArgs", {arg1}},
1614         {"MessageSeverity", "Critical"},
1615         {"Resolution",
1616          "Either the object is malformed or the URI is not correct.  "
1617          "Correct the condition and resubmit the request if it failed."}};
1618 }
1619 
1620 void invalidObject(crow::Response& res, const std::string& arg1)
1621 {
1622     res.result(boost::beast::http::status::bad_request);
1623     addMessageToErrorJson(res.jsonValue, invalidObject(arg1));
1624 }
1625 
1626 /**
1627  * @internal
1628  * @brief Formats ResourceInStandby message into JSON
1629  *
1630  * See header file for more information
1631  * @endinternal
1632  */
1633 nlohmann::json resourceInStandby(void)
1634 {
1635     return nlohmann::json{
1636         {"@odata.type", "#Message.v1_1_1.Message"},
1637         {"MessageId", "Base.1.8.1.ResourceInStandby"},
1638         {"Message", "The request could not be performed because the "
1639                     "resource is in standby."},
1640         {"MessageArgs", nlohmann::json::array()},
1641         {"MessageSeverity", "Critical"},
1642         {"Resolution", "Ensure that the resource is in the correct power "
1643                        "state and resubmit the request."}};
1644 }
1645 
1646 void resourceInStandby(crow::Response& res)
1647 {
1648     res.result(boost::beast::http::status::service_unavailable);
1649     addMessageToErrorJson(res.jsonValue, resourceInStandby());
1650 }
1651 
1652 /**
1653  * @internal
1654  * @brief Formats ActionParameterValueTypeError message into JSON
1655  *
1656  * See header file for more information
1657  * @endinternal
1658  */
1659 nlohmann::json actionParameterValueTypeError(const std::string& arg1,
1660                                              const std::string& arg2,
1661                                              const std::string& arg3)
1662 {
1663     return nlohmann::json{
1664         {"@odata.type", "#Message.v1_1_1.Message"},
1665         {"MessageId", "Base.1.8.1.ActionParameterValueTypeError"},
1666         {"Message",
1667          "The value " + arg1 + " for the parameter " + arg2 +
1668              " in the action " + arg3 +
1669              " is of a different type than the parameter can accept."},
1670         {"MessageArgs", {arg1, arg2, arg3}},
1671         {"MessageSeverity", "Warning"},
1672         {"Resolution",
1673          "Correct the value for the parameter in the request body and "
1674          "resubmit the request if the operation failed."}};
1675 }
1676 
1677 void actionParameterValueTypeError(crow::Response& res, const std::string& arg1,
1678                                    const std::string& arg2,
1679                                    const std::string& arg3)
1680 {
1681     res.result(boost::beast::http::status::bad_request);
1682     addMessageToErrorJson(res.jsonValue,
1683                           actionParameterValueTypeError(arg1, arg2, arg3));
1684 }
1685 
1686 /**
1687  * @internal
1688  * @brief Formats SessionLimitExceeded message into JSON
1689  *
1690  * See header file for more information
1691  * @endinternal
1692  */
1693 nlohmann::json sessionLimitExceeded(void)
1694 {
1695     return nlohmann::json{
1696         {"@odata.type", "#Message.v1_1_1.Message"},
1697         {"MessageId", "Base.1.8.1.SessionLimitExceeded"},
1698         {"Message", "The session establishment failed due to the number of "
1699                     "simultaneous sessions exceeding the limit of the "
1700                     "implementation."},
1701         {"MessageArgs", nlohmann::json::array()},
1702         {"MessageSeverity", "Critical"},
1703         {"Resolution", "Reduce the number of other sessions before trying "
1704                        "to establish the session or increase the limit of "
1705                        "simultaneous sessions (if supported)."}};
1706 }
1707 
1708 void sessionLimitExceeded(crow::Response& res)
1709 {
1710     res.result(boost::beast::http::status::service_unavailable);
1711     addMessageToErrorJson(res.jsonValue, sessionLimitExceeded());
1712 }
1713 
1714 /**
1715  * @internal
1716  * @brief Formats ActionNotSupported message into JSON
1717  *
1718  * See header file for more information
1719  * @endinternal
1720  */
1721 nlohmann::json actionNotSupported(const std::string& arg1)
1722 {
1723     return nlohmann::json{
1724         {"@odata.type", "#Message.v1_1_1.Message"},
1725         {"MessageId", "Base.1.8.1.ActionNotSupported"},
1726         {"Message",
1727          "The action " + arg1 + " is not supported by the resource."},
1728         {"MessageArgs", {arg1}},
1729         {"MessageSeverity", "Critical"},
1730         {"Resolution",
1731          "The action supplied cannot be resubmitted to the implementation. "
1732          " Perhaps the action was invalid, the wrong resource was the "
1733          "target or the implementation documentation may be of "
1734          "assistance."}};
1735 }
1736 
1737 void actionNotSupported(crow::Response& res, const std::string& arg1)
1738 {
1739     res.result(boost::beast::http::status::bad_request);
1740     addMessageToErrorJson(res.jsonValue, actionNotSupported(arg1));
1741 }
1742 
1743 /**
1744  * @internal
1745  * @brief Formats InvalidIndex message into JSON
1746  *
1747  * See header file for more information
1748  * @endinternal
1749  */
1750 nlohmann::json invalidIndex(const int& arg1)
1751 {
1752     return nlohmann::json{
1753         {"@odata.type", "#Message.v1_1_1.Message"},
1754         {"MessageId", "Base.1.8.1.InvalidIndex"},
1755         {"Message", "The Index " + std::to_string(arg1) +
1756                         " is not a valid offset into the array."},
1757         {"MessageArgs", {std::to_string(arg1)}},
1758         {"MessageSeverity", "Warning"},
1759         {"Resolution", "Verify the index value provided is within the "
1760                        "bounds of the array."}};
1761 }
1762 
1763 void invalidIndex(crow::Response& res, const int& arg1)
1764 {
1765     res.result(boost::beast::http::status::bad_request);
1766     addMessageToErrorJson(res.jsonValue, invalidIndex(arg1));
1767 }
1768 
1769 /**
1770  * @internal
1771  * @brief Formats EmptyJSON message into JSON
1772  *
1773  * See header file for more information
1774  * @endinternal
1775  */
1776 nlohmann::json emptyJSON(void)
1777 {
1778     return nlohmann::json{
1779         {"@odata.type", "#Message.v1_1_1.Message"},
1780         {"MessageId", "Base.1.8.1.EmptyJSON"},
1781         {"Message", "The request body submitted contained an empty JSON "
1782                     "object and the service is unable to process it."},
1783         {"MessageArgs", nlohmann::json::array()},
1784         {"MessageSeverity", "Warning"},
1785         {"Resolution",
1786          "Add properties in the JSON object and resubmit the request."}};
1787 }
1788 
1789 void emptyJSON(crow::Response& res)
1790 {
1791     res.result(boost::beast::http::status::bad_request);
1792     addMessageToErrorJson(res.jsonValue, emptyJSON());
1793 }
1794 
1795 /**
1796  * @internal
1797  * @brief Formats QueryNotSupportedOnResource message into JSON
1798  *
1799  * See header file for more information
1800  * @endinternal
1801  */
1802 nlohmann::json queryNotSupportedOnResource(void)
1803 {
1804     return nlohmann::json{
1805         {"@odata.type", "#Message.v1_1_1.Message"},
1806         {"MessageId", "Base.1.8.1.QueryNotSupportedOnResource"},
1807         {"Message", "Querying is not supported on the requested resource."},
1808         {"MessageArgs", nlohmann::json::array()},
1809         {"MessageSeverity", "Warning"},
1810         {"Resolution", "Remove the query parameters and resubmit the "
1811                        "request if the operation failed."}};
1812 }
1813 
1814 void queryNotSupportedOnResource(crow::Response& res)
1815 {
1816     res.result(boost::beast::http::status::forbidden);
1817     addMessageToErrorJson(res.jsonValue, queryNotSupportedOnResource());
1818 }
1819 
1820 /**
1821  * @internal
1822  * @brief Formats QueryNotSupportedOnOperation message into JSON
1823  *
1824  * See header file for more information
1825  * @endinternal
1826  */
1827 nlohmann::json queryNotSupportedOnOperation(void)
1828 {
1829     return nlohmann::json{
1830         {"@odata.type", "#Message.v1_1_1.Message"},
1831         {"MessageId", "Base.1.8.1.QueryNotSupportedOnOperation"},
1832         {"Message", "Querying is not supported with the requested operation."},
1833         {"MessageArgs", nlohmann::json::array()},
1834         {"MessageSeverity", "Warning"},
1835         {"Resolution", "Remove the query parameters and resubmit the request "
1836                        "if the operation failed."}};
1837 }
1838 
1839 void queryNotSupportedOnOperation(crow::Response& res)
1840 {
1841     res.result(boost::beast::http::status::forbidden);
1842     addMessageToErrorJson(res.jsonValue, queryNotSupportedOnOperation());
1843 }
1844 
1845 /**
1846  * @internal
1847  * @brief Formats QueryCombinationInvalid message into JSON
1848  *
1849  * See header file for more information
1850  * @endinternal
1851  */
1852 nlohmann::json queryCombinationInvalid(void)
1853 {
1854     return nlohmann::json{
1855         {"@odata.type", "#Message.v1_1_1.Message"},
1856         {"MessageId", "Base.1.8.1.QueryCombinationInvalid"},
1857         {"Message", "Two or more query parameters in the request cannot be "
1858                     "used together."},
1859         {"MessageArgs", nlohmann::json::array()},
1860         {"MessageSeverity", "Warning"},
1861         {"Resolution", "Remove one or more of the query parameters and "
1862                        "resubmit the request if the operation failed."}};
1863 }
1864 
1865 void queryCombinationInvalid(crow::Response& res)
1866 {
1867     res.result(boost::beast::http::status::bad_request);
1868     addMessageToErrorJson(res.jsonValue, queryCombinationInvalid());
1869 }
1870 
1871 /**
1872  * @internal
1873  * @brief Formats InsufficientPrivilege message into JSON
1874  *
1875  * See header file for more information
1876  * @endinternal
1877  */
1878 nlohmann::json insufficientPrivilege(void)
1879 {
1880     return nlohmann::json{
1881         {"@odata.type", "#Message.v1_1_1.Message"},
1882         {"MessageId", "Base.1.8.1.InsufficientPrivilege"},
1883         {"Message", "There are insufficient privileges for the account or "
1884                     "credentials associated with the current session to "
1885                     "perform the requested operation."},
1886         {"MessageArgs", nlohmann::json::array()},
1887         {"MessageSeverity", "Critical"},
1888         {"Resolution",
1889          "Either abandon the operation or change the associated access "
1890          "rights and resubmit the request if the operation failed."}};
1891 }
1892 
1893 void insufficientPrivilege(crow::Response& res)
1894 {
1895     res.result(boost::beast::http::status::forbidden);
1896     addMessageToErrorJson(res.jsonValue, insufficientPrivilege());
1897 }
1898 
1899 /**
1900  * @internal
1901  * @brief Formats PropertyValueModified message into JSON
1902  *
1903  * See header file for more information
1904  * @endinternal
1905  */
1906 nlohmann::json propertyValueModified(const std::string& arg1,
1907                                      const std::string& arg2)
1908 {
1909     return nlohmann::json{
1910         {"@odata.type", "#Message.v1_1_1.Message"},
1911         {"MessageId", "Base.1.8.1.PropertyValueModified"},
1912         {"Message", "The property " + arg1 + " was assigned the value " + arg2 +
1913                         " due to modification by the service."},
1914         {"MessageArgs", {arg1, arg2}},
1915         {"MessageSeverity", "Warning"},
1916         {"Resolution", "No resolution is required."}};
1917 }
1918 
1919 void propertyValueModified(crow::Response& res, const std::string& arg1,
1920                            const std::string& arg2)
1921 {
1922     res.result(boost::beast::http::status::ok);
1923     addMessageToJson(res.jsonValue, propertyValueModified(arg1, arg2), arg1);
1924 }
1925 
1926 /**
1927  * @internal
1928  * @brief Formats AccountNotModified message into JSON
1929  *
1930  * See header file for more information
1931  * @endinternal
1932  */
1933 nlohmann::json accountNotModified(void)
1934 {
1935     return nlohmann::json{
1936         {"@odata.type", "#Message.v1_1_1.Message"},
1937         {"MessageId", "Base.1.8.1.AccountNotModified"},
1938         {"Message", "The account modification request failed."},
1939         {"MessageArgs", nlohmann::json::array()},
1940         {"MessageSeverity", "Warning"},
1941         {"Resolution", "The modification may have failed due to permission "
1942                        "issues or issues with the request body."}};
1943 }
1944 
1945 void accountNotModified(crow::Response& res)
1946 {
1947     res.result(boost::beast::http::status::bad_request);
1948     addMessageToErrorJson(res.jsonValue, accountNotModified());
1949 }
1950 
1951 /**
1952  * @internal
1953  * @brief Formats QueryParameterValueFormatError message into JSON
1954  *
1955  * See header file for more information
1956  * @endinternal
1957  */
1958 nlohmann::json queryParameterValueFormatError(const std::string& arg1,
1959                                               const std::string& arg2)
1960 {
1961     return nlohmann::json{
1962         {"@odata.type", "#Message.v1_1_1.Message"},
1963         {"MessageId", "Base.1.8.1.QueryParameterValueFormatError"},
1964         {"Message",
1965          "The value " + arg1 + " for the parameter " + arg2 +
1966              " is of a different format than the parameter can accept."},
1967         {"MessageArgs", {arg1, arg2}},
1968         {"MessageSeverity", "Warning"},
1969         {"Resolution",
1970          "Correct the value for the query parameter in the request and "
1971          "resubmit the request if the operation failed."}};
1972 }
1973 
1974 void queryParameterValueFormatError(crow::Response& res,
1975                                     const std::string& arg1,
1976                                     const std::string& arg2)
1977 {
1978     res.result(boost::beast::http::status::bad_request);
1979     addMessageToErrorJson(res.jsonValue,
1980                           queryParameterValueFormatError(arg1, arg2));
1981 }
1982 
1983 /**
1984  * @internal
1985  * @brief Formats PropertyMissing message into JSON for the specified
1986  * property
1987  *
1988  * See header file for more information
1989  * @endinternal
1990  */
1991 nlohmann::json propertyMissing(const std::string& arg1)
1992 {
1993     return nlohmann::json{
1994         {"@odata.type", "#Message.v1_1_1.Message"},
1995         {"MessageId", "Base.1.8.1.PropertyMissing"},
1996         {"Message", "The property " + arg1 +
1997                         " is a required property and must be included in "
1998                         "the request."},
1999         {"MessageArgs", {arg1}},
2000         {"MessageSeverity", "Warning"},
2001         {"Resolution",
2002          "Ensure that the property is in the request body and has a "
2003          "valid "
2004          "value and resubmit the request if the operation failed."}};
2005 }
2006 
2007 void propertyMissing(crow::Response& res, const std::string& arg1)
2008 {
2009     res.result(boost::beast::http::status::bad_request);
2010     addMessageToJson(res.jsonValue, propertyMissing(arg1), arg1);
2011 }
2012 
2013 /**
2014  * @internal
2015  * @brief Formats ResourceExhaustion message into JSON
2016  *
2017  * See header file for more information
2018  * @endinternal
2019  */
2020 nlohmann::json resourceExhaustion(const std::string& arg1)
2021 {
2022     return nlohmann::json{
2023         {"@odata.type", "#Message.v1_1_1.Message"},
2024         {"MessageId", "Base.1.8.1.ResourceExhaustion"},
2025         {"Message", "The resource " + arg1 +
2026                         " was unable to satisfy the request due to "
2027                         "unavailability of resources."},
2028         {"MessageArgs", {arg1}},
2029         {"MessageSeverity", "Critical"},
2030         {"Resolution", "Ensure that the resources are available and "
2031                        "resubmit the request."}};
2032 }
2033 
2034 void resourceExhaustion(crow::Response& res, const std::string& arg1)
2035 {
2036     res.result(boost::beast::http::status::service_unavailable);
2037     addMessageToErrorJson(res.jsonValue, resourceExhaustion(arg1));
2038 }
2039 
2040 /**
2041  * @internal
2042  * @brief Formats AccountModified message into JSON
2043  *
2044  * See header file for more information
2045  * @endinternal
2046  */
2047 nlohmann::json accountModified(void)
2048 {
2049     return nlohmann::json{{"@odata.type", "#Message.v1_1_1.Message"},
2050                           {"MessageId", "Base.1.8.1.AccountModified"},
2051                           {"Message", "The account was successfully modified."},
2052                           {"MessageArgs", nlohmann::json::array()},
2053                           {"MessageSeverity", "OK"},
2054                           {"Resolution", "No resolution is required."}};
2055 }
2056 
2057 void accountModified(crow::Response& res)
2058 {
2059     res.result(boost::beast::http::status::ok);
2060     addMessageToErrorJson(res.jsonValue, accountModified());
2061 }
2062 
2063 /**
2064  * @internal
2065  * @brief Formats QueryParameterOutOfRange message into JSON
2066  *
2067  * See header file for more information
2068  * @endinternal
2069  */
2070 nlohmann::json queryParameterOutOfRange(const std::string& arg1,
2071                                         const std::string& arg2,
2072                                         const std::string& arg3)
2073 {
2074     return nlohmann::json{
2075         {"@odata.type", "#Message.v1_1_1.Message"},
2076         {"MessageId", "Base.1.8.1.QueryParameterOutOfRange"},
2077         {"Message", "The value " + arg1 + " for the query parameter " + arg2 +
2078                         " is out of range " + arg3 + "."},
2079         {"MessageArgs", {arg1, arg2, arg3}},
2080         {"MessageSeverity", "Warning"},
2081         {"Resolution",
2082          "Reduce the value for the query parameter to a value that is "
2083          "within range, such as a start or count value that is within "
2084          "bounds of the number of resources in a collection or a page that "
2085          "is within the range of valid pages."}};
2086 }
2087 
2088 void queryParameterOutOfRange(crow::Response& res, const std::string& arg1,
2089                               const std::string& arg2, const std::string& arg3)
2090 {
2091     res.result(boost::beast::http::status::bad_request);
2092     addMessageToErrorJson(res.jsonValue,
2093                           queryParameterOutOfRange(arg1, arg2, arg3));
2094 }
2095 
2096 /**
2097  * @internal
2098  * @brief Formats PasswordChangeRequired message into JSON
2099  *
2100  * See header file for more information
2101  * @endinternal
2102  */
2103 void passwordChangeRequired(crow::Response& res, const std::string& arg1)
2104 {
2105     messages::addMessageToJsonRoot(
2106         res.jsonValue,
2107         nlohmann::json{
2108             {"@odata.type", "/redfish/v1/$metadata#Message.v1_5_0.Message"},
2109             {"MessageId", "Base.1.8.1.PasswordChangeRequired"},
2110             {"Message", "The password provided for this account must be "
2111                         "changed before access is granted.  PATCH the "
2112                         "'Password' property for this account located at "
2113                         "the target URI '" +
2114                             arg1 + "' to complete this process."},
2115             {"MessageArgs", {arg1}},
2116             {"MessageSeverity", "Critical"},
2117             {"Resolution", "Change the password for this account using "
2118                            "a PATCH to the 'Password' property at the URI "
2119                            "provided."}});
2120 }
2121 
2122 void invalidUpload(crow::Response& res, const std::string& arg1,
2123                    const std::string& arg2)
2124 {
2125     res.result(boost::beast::http::status::bad_request);
2126     addMessageToErrorJson(res.jsonValue, invalidUpload(arg1, arg2));
2127 }
2128 
2129 /**
2130  * @internal
2131  * @brief Formats Invalid File message into JSON
2132  *
2133  * See header file for more information
2134  * @endinternal
2135  */
2136 nlohmann::json invalidUpload(const std::string& arg1, const std::string& arg2)
2137 {
2138     return nlohmann::json{
2139         {"@odata.type", "/redfish/v1/$metadata#Message.v1_1_1.Message"},
2140         {"MessageId", "OpenBMC.0.2.InvalidUpload"},
2141         {"Message", "Invalid file uploaded to " + arg1 + ": " + arg2 + "."},
2142         {"MessageArgs", {arg1, arg2}},
2143         {"MessageSeverity", "Warning"},
2144         {"Resolution", "None."}};
2145 }
2146 
2147 /**
2148  * @internal
2149  * @brief Formats MutualExclusiveProperties into JSON
2150  *
2151  * See header file for more information
2152  * @endinternal
2153  */
2154 nlohmann::json mutualExclusiveProperties(const std::string& arg1,
2155                                          const std::string& arg2)
2156 {
2157     return nlohmann::json{
2158         {"@odata.type", "#Message.v1_1_1.Message"},
2159         {"MessageId", "Base.1.5.0.MutualExclusiveProperties"},
2160         {"Message", "The properties " + arg1 + " and " + arg2 +
2161                         " are mutually exclusive."},
2162         {"MessageArgs", {arg1, arg2}},
2163         {"MessageSeverity", "Warning"},
2164         {"Resolution",
2165          "Ensure that the request body doesn't contain mutually exclusive "
2166          "properties and resubmit the request."}};
2167 }
2168 
2169 void mutualExclusiveProperties(crow::Response& res, const std::string& arg1,
2170                                const std::string& arg2)
2171 {
2172     res.result(boost::beast::http::status::bad_request);
2173     addMessageToErrorJson(res.jsonValue, mutualExclusiveProperties(arg1, arg2));
2174 }
2175 
2176 } // namespace messages
2177 
2178 } // namespace redfish
2179