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