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 <crow/logging.h> 17 18 #include <error_messages.hpp> 19 20 namespace redfish 21 { 22 23 namespace messages 24 { 25 26 static void addMessageToErrorJson(nlohmann::json& target, 27 const nlohmann::json& message) 28 { 29 auto& error = target["error"]; 30 31 // If this is the first error message, fill in the information from the 32 // first error message to the top level struct 33 if (!error.is_object()) 34 { 35 auto message_id_iterator = message.find("MessageId"); 36 if (message_id_iterator == message.end()) 37 { 38 BMCWEB_LOG_CRITICAL 39 << "Attempt to add error message without MessageId"; 40 return; 41 } 42 43 auto message_field_iterator = message.find("Message"); 44 if (message_field_iterator == message.end()) 45 { 46 BMCWEB_LOG_CRITICAL 47 << "Attempt to add error message without Message"; 48 return; 49 } 50 // clang-format off 51 error = { 52 {"code", *message_id_iterator}, 53 {"message", *message_field_iterator} 54 }; 55 // clang-format on 56 } 57 else 58 { 59 // More than 1 error occurred, so the message has to be generic 60 error["code"] = std::string(messageVersionPrefix) + "GeneralError"; 61 error["message"] = "A general error has occurred. See Resolution for " 62 "information on how to resolve the error."; 63 } 64 65 // This check could technically be done in in the default construction 66 // branch above, but because we need the pointer to the extended info field 67 // anyway, it's more efficient to do it here. 68 auto& extended_info = error[messages::messageAnnotation]; 69 if (!extended_info.is_array()) 70 { 71 extended_info = nlohmann::json::array(); 72 } 73 74 extended_info.push_back(message); 75 } 76 77 static void addMessageToJsonRoot(nlohmann::json& target, 78 const nlohmann::json& message) 79 { 80 if (!target[messages::messageAnnotation].is_array()) 81 { 82 // Force object to be an array 83 target[messages::messageAnnotation] = nlohmann::json::array(); 84 } 85 86 target[messages::messageAnnotation].push_back(message); 87 } 88 89 static void addMessageToJson(nlohmann::json& target, 90 const nlohmann::json& message, 91 const std::string& fieldPath) 92 { 93 std::string extendedInfo(fieldPath + messages::messageAnnotation); 94 95 if (!target[extendedInfo].is_array()) 96 { 97 // Force object to be an array 98 target[extendedInfo] = nlohmann::json::array(); 99 } 100 101 // Object exists and it is an array so we can just push in the message 102 target[extendedInfo].push_back(message); 103 } 104 105 /** 106 * @internal 107 * @brief Formats ResourceInUse message into JSON 108 * 109 * See header file for more information 110 * @endinternal 111 */ 112 void resourceInUse(crow::Response& res) 113 { 114 res.result(boost::beast::http::status::service_unavailable); 115 addMessageToErrorJson( 116 res.jsonValue, 117 nlohmann::json{ 118 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 119 {"MessageId", "Base.1.4.0.ResourceInUse"}, 120 {"Message", "The change to the requested resource failed because " 121 "the resource is in use or in transition."}, 122 {"MessageArgs", nlohmann::json::array()}, 123 {"Severity", "Warning"}, 124 {"Resolution", "Remove the condition and resubmit the request if " 125 "the operation failed."}}); 126 } 127 128 /** 129 * @internal 130 * @brief Formats MalformedJSON message into JSON 131 * 132 * See header file for more information 133 * @endinternal 134 */ 135 void malformedJSON(crow::Response& res) 136 { 137 res.result(boost::beast::http::status::bad_request); 138 addMessageToErrorJson( 139 res.jsonValue, 140 nlohmann::json{ 141 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 142 {"MessageId", "Base.1.4.0.MalformedJSON"}, 143 {"Message", "The request body submitted was malformed JSON and " 144 "could not be parsed by the receiving service."}, 145 {"MessageArgs", nlohmann::json::array()}, 146 {"Severity", "Critical"}, 147 {"Resolution", "Ensure that the request body is valid JSON and " 148 "resubmit the request."}}); 149 } 150 151 /** 152 * @internal 153 * @brief Formats ResourceMissingAtURI message into JSON 154 * 155 * See header file for more information 156 * @endinternal 157 */ 158 void resourceMissingAtURI(crow::Response& res, const std::string& arg1) 159 { 160 res.result(boost::beast::http::status::bad_request); 161 addMessageToErrorJson( 162 res.jsonValue, 163 nlohmann::json{ 164 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 165 {"MessageId", "Base.1.4.0.ResourceMissingAtURI"}, 166 {"Message", "The resource at the URI " + arg1 + " was not found."}, 167 {"MessageArgs", {arg1}}, 168 {"Severity", "Critical"}, 169 {"Resolution", "Place a valid resource at the URI or correct the " 170 "URI and resubmit the request."}}); 171 } 172 173 /** 174 * @internal 175 * @brief Formats ActionParameterValueFormatError message into JSON 176 * 177 * See header file for more information 178 * @endinternal 179 */ 180 void actionParameterValueFormatError(crow::Response& res, 181 const std::string& arg1, 182 const std::string& arg2, 183 const std::string& arg3) 184 { 185 res.result(boost::beast::http::status::bad_request); 186 addMessageToErrorJson( 187 res.jsonValue, 188 nlohmann::json{ 189 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 190 {"MessageId", "Base.1.4.0.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 {"Severity", "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 /** 203 * @internal 204 * @brief Formats InternalError message into JSON 205 * 206 * See header file for more information 207 * @endinternal 208 */ 209 void internalError(crow::Response& res) 210 { 211 res.result(boost::beast::http::status::internal_server_error); 212 addMessageToErrorJson( 213 res.jsonValue, 214 nlohmann::json{ 215 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 216 {"MessageId", "Base.1.4.0.InternalError"}, 217 {"Message", "The request failed due to an internal service error. " 218 "The service is still operational."}, 219 {"MessageArgs", nlohmann::json::array()}, 220 {"Severity", "Critical"}, 221 {"Resolution", "Resubmit the request. If the problem persists, " 222 "consider resetting the service."}}); 223 } 224 225 /** 226 * @internal 227 * @brief Formats UnrecognizedRequestBody message into JSON 228 * 229 * See header file for more information 230 * @endinternal 231 */ 232 void unrecognizedRequestBody(crow::Response& res) 233 { 234 res.result(boost::beast::http::status::bad_request); 235 addMessageToErrorJson( 236 res.jsonValue, 237 nlohmann::json{ 238 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 239 {"MessageId", "Base.1.4.0.UnrecognizedRequestBody"}, 240 {"Message", "The service detected a malformed request body that it " 241 "was unable to interpret."}, 242 {"MessageArgs", nlohmann::json::array()}, 243 {"Severity", "Warning"}, 244 {"Resolution", "Correct the request body and resubmit the request " 245 "if it failed."}}); 246 } 247 248 /** 249 * @internal 250 * @brief Formats ResourceAtUriUnauthorized message into JSON 251 * 252 * See header file for more information 253 * @endinternal 254 */ 255 void resourceAtUriUnauthorized(crow::Response& res, const std::string& arg1, 256 const std::string& arg2) 257 { 258 res.result(boost::beast::http::status::forbidden); 259 addMessageToErrorJson( 260 res.jsonValue, 261 nlohmann::json{ 262 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 263 {"MessageId", "Base.1.4.0.ResourceAtUriUnauthorized"}, 264 {"Message", "While accessing the resource at " + arg1 + 265 ", the service received an authorization error " + 266 arg2 + "."}, 267 {"MessageArgs", {arg1, arg2}}, 268 {"Severity", "Critical"}, 269 {"Resolution", "Ensure that the appropriate access is provided for " 270 "the service in order for it to access the URI."}}); 271 } 272 273 /** 274 * @internal 275 * @brief Formats ActionParameterUnknown message into JSON 276 * 277 * See header file for more information 278 * @endinternal 279 */ 280 void actionParameterUnknown(crow::Response& res, const std::string& arg1, 281 const std::string& arg2) 282 { 283 res.result(boost::beast::http::status::bad_request); 284 addMessageToErrorJson( 285 res.jsonValue, 286 nlohmann::json{ 287 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 288 {"MessageId", "Base.1.4.0.ActionParameterUnknown"}, 289 {"Message", "The action " + arg1 + 290 " was submitted with the invalid parameter " + 291 arg2 + "."}, 292 {"MessageArgs", {arg1, arg2}}, 293 {"Severity", "Warning"}, 294 {"Resolution", "Correct the invalid parameter and resubmit the " 295 "request if the operation failed."}}); 296 } 297 298 /** 299 * @internal 300 * @brief Formats ResourceCannotBeDeleted message into JSON 301 * 302 * See header file for more information 303 * @endinternal 304 */ 305 void resourceCannotBeDeleted(crow::Response& res) 306 { 307 res.result(boost::beast::http::status::forbidden); 308 addMessageToErrorJson( 309 res.jsonValue, 310 nlohmann::json{ 311 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 312 {"MessageId", "Base.1.4.0.ResourceCannotBeDeleted"}, 313 {"Message", "The delete request failed because the resource " 314 "requested cannot be deleted."}, 315 {"MessageArgs", nlohmann::json::array()}, 316 {"Severity", "Critical"}, 317 {"Resolution", 318 "Do not attempt to delete a non-deletable resource."}}); 319 } 320 321 /** 322 * @internal 323 * @brief Formats PropertyDuplicate message into JSON 324 * 325 * See header file for more information 326 * @endinternal 327 */ 328 void propertyDuplicate(crow::Response& res, const std::string& arg1) 329 { 330 res.result(boost::beast::http::status::bad_request); 331 addMessageToJson( 332 res.jsonValue, 333 nlohmann::json{ 334 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 335 {"MessageId", "Base.1.4.0.PropertyDuplicate"}, 336 {"Message", 337 "The property " + arg1 + " was duplicated in the request."}, 338 {"MessageArgs", {arg1}}, 339 {"Severity", "Warning"}, 340 {"Resolution", 341 "Remove the duplicate property from the request body and resubmit " 342 "the request if the operation failed."}}, 343 arg1); 344 } 345 346 /** 347 * @internal 348 * @brief Formats ServiceTemporarilyUnavailable message into JSON 349 * 350 * See header file for more information 351 * @endinternal 352 */ 353 void serviceTemporarilyUnavailable(crow::Response& res, const std::string& arg1) 354 { 355 res.result(boost::beast::http::status::service_unavailable); 356 addMessageToErrorJson( 357 res.jsonValue, 358 nlohmann::json{ 359 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 360 {"MessageId", "Base.1.4.0.ServiceTemporarilyUnavailable"}, 361 {"Message", "The service is temporarily unavailable. Retry in " + 362 arg1 + " seconds."}, 363 {"MessageArgs", {arg1}}, 364 {"Severity", "Critical"}, 365 {"Resolution", "Wait for the indicated retry duration and retry " 366 "the operation."}}); 367 } 368 369 /** 370 * @internal 371 * @brief Formats ResourceAlreadyExists message into JSON 372 * 373 * See header file for more information 374 * @endinternal 375 */ 376 void resourceAlreadyExists(crow::Response& res, const std::string& arg1, 377 const std::string& arg2, const std::string& arg3) 378 { 379 res.result(boost::beast::http::status::bad_request); 380 addMessageToJson( 381 res.jsonValue, 382 nlohmann::json{ 383 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 384 {"MessageId", "Base.1.4.0.ResourceAlreadyExists"}, 385 {"Message", "The requested resource of type " + arg1 + 386 " with the property " + arg2 + " with the value " + 387 arg3 + " already exists."}, 388 {"MessageArgs", {arg1, arg2, arg3}}, 389 {"Severity", "Critical"}, 390 {"Resolution", "Do not repeat the create operation as the resource " 391 "has already been created."}}, 392 arg2); 393 } 394 395 /** 396 * @internal 397 * @brief Formats AccountForSessionNoLongerExists message into JSON 398 * 399 * See header file for more information 400 * @endinternal 401 */ 402 void accountForSessionNoLongerExists(crow::Response& res) 403 { 404 res.result(boost::beast::http::status::forbidden); 405 addMessageToErrorJson( 406 res.jsonValue, 407 nlohmann::json{ 408 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 409 {"MessageId", "Base.1.4.0.AccountForSessionNoLongerExists"}, 410 {"Message", "The account for the current session has been removed, " 411 "thus the current session has been removed as well."}, 412 {"MessageArgs", nlohmann::json::array()}, 413 {"Severity", "OK"}, 414 {"Resolution", "Attempt to connect with a valid account."}}); 415 } 416 417 /** 418 * @internal 419 * @brief Formats CreateFailedMissingReqProperties message into JSON 420 * 421 * See header file for more information 422 * @endinternal 423 */ 424 void createFailedMissingReqProperties(crow::Response& res, 425 const std::string& arg1) 426 { 427 res.result(boost::beast::http::status::bad_request); 428 addMessageToJson( 429 res.jsonValue, 430 nlohmann::json{ 431 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 432 {"MessageId", "Base.1.4.0.CreateFailedMissingReqProperties"}, 433 {"Message", 434 "The create operation failed because the required property " + 435 arg1 + " was missing from the request."}, 436 {"MessageArgs", {arg1}}, 437 {"Severity", "Critical"}, 438 {"Resolution", 439 "Correct the body to include the required property with a valid " 440 "value and resubmit the request if the operation failed."}}, 441 arg1); 442 } 443 444 /** 445 * @internal 446 * @brief Formats PropertyValueFormatError message into JSON for the specified 447 * property 448 * 449 * See header file for more information 450 * @endinternal 451 */ 452 void propertyValueFormatError(crow::Response& res, const std::string& arg1, 453 const std::string& arg2) 454 { 455 res.result(boost::beast::http::status::bad_request); 456 addMessageToJson( 457 res.jsonValue, 458 nlohmann::json{ 459 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 460 {"MessageId", "Base.1.4.0.PropertyValueFormatError"}, 461 {"Message", 462 "The value " + arg1 + " for the property " + arg2 + 463 " is of a different format than the property can accept."}, 464 {"MessageArgs", {arg1, arg2}}, 465 {"Severity", "Warning"}, 466 {"Resolution", 467 "Correct the value for the property in the request body and " 468 "resubmit the request if the operation failed."}}, 469 arg2); 470 } 471 472 /** 473 * @internal 474 * @brief Formats PropertyValueNotInList message into JSON for the specified 475 * property 476 * 477 * See header file for more information 478 * @endinternal 479 */ 480 void propertyValueNotInList(crow::Response& res, const std::string& arg1, 481 const std::string& arg2) 482 { 483 res.result(boost::beast::http::status::bad_request); 484 addMessageToJson( 485 res.jsonValue, 486 nlohmann::json{ 487 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 488 {"MessageId", "Base.1.4.0.PropertyValueNotInList"}, 489 {"Message", "The value " + arg1 + " for the property " + arg2 + 490 " is not in the list of acceptable values."}, 491 {"MessageArgs", {arg1, arg2}}, 492 {"Severity", "Warning"}, 493 {"Resolution", 494 "Choose a value from the enumeration list that the implementation " 495 "can support and resubmit the request if the operation failed."}}, 496 arg2); 497 } 498 499 /** 500 * @internal 501 * @brief Formats ResourceAtUriInUnknownFormat message into JSON 502 * 503 * See header file for more information 504 * @endinternal 505 */ 506 void resourceAtUriInUnknownFormat(crow::Response& res, const std::string& arg1) 507 { 508 res.result(boost::beast::http::status::bad_request); 509 addMessageToErrorJson( 510 res.jsonValue, 511 nlohmann::json{ 512 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 513 {"MessageId", "Base.1.4.0.ResourceAtUriInUnknownFormat"}, 514 {"Message", "The resource at " + arg1 + 515 " is in a format not recognized by the service."}, 516 {"MessageArgs", {arg1}}, 517 {"Severity", "Critical"}, 518 {"Resolution", "Place an image or resource or file that is " 519 "recognized by the service at the URI."}}); 520 } 521 522 /** 523 * @internal 524 * @brief Formats ServiceInUnknownState message into JSON 525 * 526 * See header file for more information 527 * @endinternal 528 */ 529 void serviceInUnknownState(crow::Response& res) 530 { 531 res.result(boost::beast::http::status::service_unavailable); 532 addMessageToErrorJson( 533 res.jsonValue, 534 nlohmann::json{ 535 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 536 {"MessageId", "Base.1.4.0.ServiceInUnknownState"}, 537 {"Message", 538 "The operation failed because the service is in an unknown state " 539 "and can no longer take incoming requests."}, 540 {"MessageArgs", nlohmann::json::array()}, 541 {"Severity", "Critical"}, 542 {"Resolution", "Restart the service and resubmit the request if " 543 "the operation failed."}}); 544 } 545 546 /** 547 * @internal 548 * @brief Formats EventSubscriptionLimitExceeded message into JSON 549 * 550 * See header file for more information 551 * @endinternal 552 */ 553 void eventSubscriptionLimitExceeded(crow::Response& res) 554 { 555 res.result(boost::beast::http::status::forbidden); 556 addMessageToErrorJson( 557 res.jsonValue, 558 nlohmann::json{ 559 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 560 {"MessageId", "Base.1.4.0.EventSubscriptionLimitExceeded"}, 561 {"Message", 562 "The event subscription failed due to the number of simultaneous " 563 "subscriptions exceeding the limit of the implementation."}, 564 {"MessageArgs", nlohmann::json::array()}, 565 {"Severity", "Critical"}, 566 {"Resolution", 567 "Reduce the number of other subscriptions before trying to " 568 "establish the event subscription or increase the limit of " 569 "simultaneous subscriptions (if supported)."}}); 570 } 571 572 /** 573 * @internal 574 * @brief Formats ActionParameterMissing message into JSON 575 * 576 * See header file for more information 577 * @endinternal 578 */ 579 void actionParameterMissing(crow::Response& res, const std::string& arg1, 580 const std::string& arg2) 581 { 582 res.result(boost::beast::http::status::bad_request); 583 addMessageToErrorJson( 584 res.jsonValue, 585 nlohmann::json{ 586 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 587 {"MessageId", "Base.1.4.0.ActionParameterMissing"}, 588 {"Message", "The action " + arg1 + " requires the parameter " + 589 arg2 + " to be present in the request body."}, 590 {"MessageArgs", {arg1, arg2}}, 591 {"Severity", "Critical"}, 592 {"Resolution", 593 "Supply the action with the required parameter in the request " 594 "body when the request is resubmitted."}}); 595 } 596 597 /** 598 * @internal 599 * @brief Formats StringValueTooLong message into JSON 600 * 601 * See header file for more information 602 * @endinternal 603 */ 604 void stringValueTooLong(crow::Response& res, const std::string& arg1, 605 const int& arg2) 606 { 607 res.result(boost::beast::http::status::bad_request); 608 addMessageToErrorJson( 609 res.jsonValue, 610 nlohmann::json{ 611 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 612 {"MessageId", "Base.1.4.0.StringValueTooLong"}, 613 {"Message", "The string " + arg1 + " exceeds the length limit " + 614 std::to_string(arg2) + "."}, 615 {"MessageArgs", {arg1, std::to_string(arg2)}}, 616 {"Severity", "Warning"}, 617 {"Resolution", 618 "Resubmit the request with an appropriate string length."}}); 619 } 620 621 /** 622 * @internal 623 * @brief Formats SessionTerminated message into JSON 624 * 625 * See header file for more information 626 * @endinternal 627 */ 628 void sessionTerminated(crow::Response& res) 629 { 630 res.result(boost::beast::http::status::ok); 631 addMessageToJsonRoot( 632 res.jsonValue, 633 nlohmann::json{ 634 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 635 {"MessageId", "Base.1.4.0.SessionTerminated"}, 636 {"Message", "The session was successfully terminated."}, 637 {"MessageArgs", nlohmann::json::array()}, 638 {"Severity", "OK"}, 639 {"Resolution", "No resolution is required."}}); 640 } 641 642 /** 643 * @internal 644 * @brief Formats ResourceTypeIncompatible message into JSON 645 * 646 * See header file for more information 647 * @endinternal 648 */ 649 void resourceTypeIncompatible(crow::Response& res, const std::string& arg1, 650 const std::string& arg2) 651 { 652 res.result(boost::beast::http::status::bad_request); 653 addMessageToErrorJson( 654 res.jsonValue, 655 nlohmann::json{ 656 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 657 {"MessageId", "Base.1.4.0.ResourceTypeIncompatible"}, 658 {"Message", "The @odata.type of the request body " + arg1 + 659 " is incompatible with the @odata.type of the " 660 "resource which is " + 661 arg2 + "."}, 662 {"MessageArgs", {arg1, arg2}}, 663 {"Severity", "Critical"}, 664 {"Resolution", "Resubmit the request with a payload compatible " 665 "with the resource's schema."}}); 666 } 667 668 /** 669 * @internal 670 * @brief Formats PropertyValueTypeError message into JSON for the specified 671 * property 672 * 673 * See header file for more information 674 * @endinternal 675 */ 676 void propertyValueTypeError(crow::Response& res, const std::string& arg1, 677 const std::string& arg2) 678 { 679 res.result(boost::beast::http::status::bad_request); 680 addMessageToJson( 681 res.jsonValue, 682 nlohmann::json{ 683 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 684 {"MessageId", "Base.1.4.0.PropertyValueTypeError"}, 685 {"Message", 686 "The value " + arg1 + " for the property " + arg2 + 687 " is of a different type than the property can accept."}, 688 {"MessageArgs", {arg1, arg2}}, 689 {"Severity", "Warning"}, 690 {"Resolution", 691 "Correct the value for the property in the request body and " 692 "resubmit the request if the operation failed."}}, 693 arg2); 694 } 695 696 /** 697 * @internal 698 * @brief Formats ResourceNotFound message into JSON 699 * 700 * See header file for more information 701 * @endinternal 702 */ 703 void resourceNotFound(crow::Response& res, const std::string& arg1, 704 const std::string& arg2) 705 { 706 res.result(boost::beast::http::status::not_found); 707 addMessageToErrorJson( 708 res.jsonValue, 709 nlohmann::json{ 710 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 711 {"MessageId", "Base.1.4.0.ResourceNotFound"}, 712 {"Message", "The requested resource of type " + arg1 + " named " + 713 arg2 + " was not found."}, 714 {"MessageArgs", {arg1, arg2}}, 715 {"Severity", "Critical"}, 716 {"Resolution", 717 "Provide a valid resource identifier and resubmit the request."}}); 718 } 719 720 /** 721 * @internal 722 * @brief Formats CouldNotEstablishConnection message into JSON 723 * 724 * See header file for more information 725 * @endinternal 726 */ 727 void couldNotEstablishConnection(crow::Response& res, const std::string& arg1) 728 { 729 res.result(boost::beast::http::status::not_found); 730 addMessageToErrorJson( 731 res.jsonValue, 732 nlohmann::json{ 733 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 734 {"MessageId", "Base.1.4.0.CouldNotEstablishConnection"}, 735 {"Message", 736 "The service failed to establish a Connection with the URI " + 737 arg1 + "."}, 738 {"MessageArgs", {arg1}}, 739 {"Severity", "Critical"}, 740 {"Resolution", 741 "Ensure that the URI contains a valid and reachable node name, " 742 "protocol information and other URI components."}}); 743 } 744 745 /** 746 * @internal 747 * @brief Formats PropertyNotWritable message into JSON for the specified 748 * property 749 * 750 * See header file for more information 751 * @endinternal 752 */ 753 void propertyNotWritable(crow::Response& res, const std::string& arg1) 754 { 755 res.result(boost::beast::http::status::forbidden); 756 addMessageToJson( 757 res.jsonValue, 758 nlohmann::json{ 759 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 760 {"MessageId", "Base.1.4.0.PropertyNotWritable"}, 761 {"Message", 762 "The property " + arg1 + 763 " is a read only property and cannot be assigned a value."}, 764 {"MessageArgs", {arg1}}, 765 {"Severity", "Warning"}, 766 {"Resolution", "Remove the property from the request body and " 767 "resubmit the request if the operation failed."}}, 768 arg1); 769 } 770 771 /** 772 * @internal 773 * @brief Formats QueryParameterValueTypeError message into JSON 774 * 775 * See header file for more information 776 * @endinternal 777 */ 778 void queryParameterValueTypeError(crow::Response& res, const std::string& arg1, 779 const std::string& arg2) 780 { 781 res.result(boost::beast::http::status::bad_request); 782 addMessageToErrorJson( 783 res.jsonValue, 784 nlohmann::json{ 785 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 786 {"MessageId", "Base.1.4.0.QueryParameterValueTypeError"}, 787 {"Message", 788 "The value " + arg1 + " for the query parameter " + arg2 + 789 " is of a different type than the parameter can accept."}, 790 {"MessageArgs", {arg1, arg2}}, 791 {"Severity", "Warning"}, 792 {"Resolution", 793 "Correct the value for the query parameter in the request and " 794 "resubmit the request if the operation failed."}}); 795 } 796 797 /** 798 * @internal 799 * @brief Formats ServiceShuttingDown message into JSON 800 * 801 * See header file for more information 802 * @endinternal 803 */ 804 void serviceShuttingDown(crow::Response& res) 805 { 806 res.result(boost::beast::http::status::service_unavailable); 807 addMessageToErrorJson( 808 res.jsonValue, 809 nlohmann::json{ 810 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 811 {"MessageId", "Base.1.4.0.ServiceShuttingDown"}, 812 {"Message", "The operation failed because the service is shutting " 813 "down and can no longer take incoming requests."}, 814 {"MessageArgs", nlohmann::json::array()}, 815 {"Severity", "Critical"}, 816 {"Resolution", "When the service becomes available, resubmit the " 817 "request if the operation failed."}}); 818 } 819 820 /** 821 * @internal 822 * @brief Formats ActionParameterDuplicate message into JSON 823 * 824 * See header file for more information 825 * @endinternal 826 */ 827 void actionParameterDuplicate(crow::Response& res, const std::string& arg1, 828 const std::string& arg2) 829 { 830 res.result(boost::beast::http::status::bad_request); 831 addMessageToErrorJson( 832 res.jsonValue, 833 nlohmann::json{ 834 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 835 {"MessageId", "Base.1.4.0.ActionParameterDuplicate"}, 836 {"Message", 837 "The action " + arg1 + 838 " was submitted with more than one value for the parameter " + 839 arg2 + "."}, 840 {"MessageArgs", {arg1, arg2}}, 841 {"Severity", "Warning"}, 842 {"Resolution", 843 "Resubmit the action with only one instance of the parameter in " 844 "the request body if the operation failed."}}); 845 } 846 847 /** 848 * @internal 849 * @brief Formats ActionParameterNotSupported message into JSON 850 * 851 * See header file for more information 852 * @endinternal 853 */ 854 void actionParameterNotSupported(crow::Response& res, const std::string& arg1, 855 const std::string& arg2) 856 { 857 res.result(boost::beast::http::status::bad_request); 858 addMessageToErrorJson( 859 res.jsonValue, 860 nlohmann::json{ 861 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 862 {"MessageId", "Base.1.4.0.ActionParameterNotSupported"}, 863 {"Message", "The parameter " + arg1 + " for the action " + arg2 + 864 " is not supported on the target resource."}, 865 {"MessageArgs", {arg1, arg2}}, 866 {"Severity", "Warning"}, 867 {"Resolution", "Remove the parameter supplied and resubmit the " 868 "request if the operation failed."}}); 869 } 870 871 /** 872 * @internal 873 * @brief Formats SourceDoesNotSupportProtocol message into JSON 874 * 875 * See header file for more information 876 * @endinternal 877 */ 878 void sourceDoesNotSupportProtocol(crow::Response& res, const std::string& arg1, 879 const std::string& arg2) 880 { 881 res.result(boost::beast::http::status::bad_request); 882 addMessageToErrorJson( 883 res.jsonValue, 884 nlohmann::json{ 885 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 886 {"MessageId", "Base.1.4.0.SourceDoesNotSupportProtocol"}, 887 {"Message", "The other end of the Connection at " + arg1 + 888 " does not support the specified protocol " + arg2 + 889 "."}, 890 {"MessageArgs", {arg1, arg2}}, 891 {"Severity", "Critical"}, 892 {"Resolution", "Change protocols or URIs. "}}); 893 } 894 895 /** 896 * @internal 897 * @brief Formats AccountRemoved message into JSON 898 * 899 * See header file for more information 900 * @endinternal 901 */ 902 void accountRemoved(crow::Response& res) 903 { 904 res.result(boost::beast::http::status::ok); 905 addMessageToJsonRoot( 906 res.jsonValue, 907 nlohmann::json{ 908 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 909 {"MessageId", "Base.1.4.0.AccountRemoved"}, 910 {"Message", "The account was successfully removed."}, 911 {"MessageArgs", nlohmann::json::array()}, 912 {"Severity", "OK"}, 913 {"Resolution", "No resolution is required."}}); 914 } 915 916 /** 917 * @internal 918 * @brief Formats AccessDenied message into JSON 919 * 920 * See header file for more information 921 * @endinternal 922 */ 923 void accessDenied(crow::Response& res, const std::string& arg1) 924 { 925 res.result(boost::beast::http::status::forbidden); 926 addMessageToErrorJson( 927 res.jsonValue, 928 nlohmann::json{ 929 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 930 {"MessageId", "Base.1.4.0.AccessDenied"}, 931 {"Message", "While attempting to establish a Connection to " + 932 arg1 + ", the service denied access."}, 933 {"MessageArgs", {arg1}}, 934 {"Severity", "Critical"}, 935 {"Resolution", "Attempt to ensure that the URI is correct and that " 936 "the service has the appropriate credentials."}}); 937 } 938 939 /** 940 * @internal 941 * @brief Formats QueryNotSupported message into JSON 942 * 943 * See header file for more information 944 * @endinternal 945 */ 946 void queryNotSupported(crow::Response& res) 947 { 948 res.result(boost::beast::http::status::bad_request); 949 addMessageToErrorJson( 950 res.jsonValue, 951 nlohmann::json{ 952 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 953 {"MessageId", "Base.1.4.0.QueryNotSupported"}, 954 {"Message", "Querying is not supported by the implementation."}, 955 {"MessageArgs", nlohmann::json::array()}, 956 {"Severity", "Warning"}, 957 {"Resolution", "Remove the query parameters and resubmit the " 958 "request if the operation failed."}}); 959 } 960 961 /** 962 * @internal 963 * @brief Formats CreateLimitReachedForResource message into JSON 964 * 965 * See header file for more information 966 * @endinternal 967 */ 968 void createLimitReachedForResource(crow::Response& res) 969 { 970 res.result(boost::beast::http::status::bad_request); 971 addMessageToErrorJson( 972 res.jsonValue, 973 nlohmann::json{ 974 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 975 {"MessageId", "Base.1.4.0.CreateLimitReachedForResource"}, 976 {"Message", "The create operation failed because the resource has " 977 "reached the limit of possible resources."}, 978 {"MessageArgs", nlohmann::json::array()}, 979 {"Severity", "Critical"}, 980 {"Resolution", 981 "Either delete resources and resubmit the request if the " 982 "operation failed or do not resubmit the request."}}); 983 } 984 985 /** 986 * @internal 987 * @brief Formats GeneralError message into JSON 988 * 989 * See header file for more information 990 * @endinternal 991 */ 992 void generalError(crow::Response& res) 993 { 994 res.result(boost::beast::http::status::internal_server_error); 995 addMessageToErrorJson( 996 res.jsonValue, 997 nlohmann::json{ 998 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 999 {"MessageId", "Base.1.4.0.GeneralError"}, 1000 {"Message", "A general error has occurred. See Resolution for " 1001 "information on how to resolve the error."}, 1002 {"MessageArgs", nlohmann::json::array()}, 1003 {"Severity", "Critical"}, 1004 {"Resolution", "None."}}); 1005 } 1006 1007 /** 1008 * @internal 1009 * @brief Formats Success message into JSON 1010 * 1011 * See header file for more information 1012 * @endinternal 1013 */ 1014 void success(crow::Response& res) 1015 { 1016 res.result(boost::beast::http::status::ok); 1017 addMessageToJsonRoot( 1018 res.jsonValue, 1019 nlohmann::json{ 1020 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1021 {"MessageId", "Base.1.4.0.Success"}, 1022 {"Message", "Successfully Completed Request"}, 1023 {"MessageArgs", nlohmann::json::array()}, 1024 {"Severity", "OK"}, 1025 {"Resolution", "None"}}); 1026 } 1027 1028 /** 1029 * @internal 1030 * @brief Formats Created message into JSON 1031 * 1032 * See header file for more information 1033 * @endinternal 1034 */ 1035 void created(crow::Response& res) 1036 { 1037 res.result(boost::beast::http::status::created); 1038 addMessageToJsonRoot( 1039 res.jsonValue, 1040 nlohmann::json{ 1041 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1042 {"MessageId", "Base.1.4.0.Created"}, 1043 {"Message", "The resource has been created successfully"}, 1044 {"MessageArgs", nlohmann::json::array()}, 1045 {"Severity", "OK"}, 1046 {"Resolution", "None"}}); 1047 } 1048 1049 /** 1050 * @internal 1051 * @brief Formats NoOperation message into JSON 1052 * 1053 * See header file for more information 1054 * @endinternal 1055 */ 1056 void noOperation(crow::Response& res) 1057 { 1058 res.result(boost::beast::http::status::bad_request); 1059 addMessageToErrorJson( 1060 res.jsonValue, 1061 nlohmann::json{ 1062 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1063 {"MessageId", "Base.1.4.0.NoOperation"}, 1064 {"Message", "The request body submitted contain no data to act " 1065 "upon and no changes to the resource took place."}, 1066 {"MessageArgs", nlohmann::json::array()}, 1067 {"Severity", "Warning"}, 1068 {"Resolution", 1069 "Add properties in the JSON object and resubmit the request."}}); 1070 } 1071 1072 /** 1073 * @internal 1074 * @brief Formats PropertyUnknown message into JSON for the specified property 1075 * 1076 * See header file for more information 1077 * @endinternal 1078 */ 1079 void propertyUnknown(crow::Response& res, const std::string& arg1) 1080 { 1081 res.result(boost::beast::http::status::bad_request); 1082 addMessageToJson( 1083 res.jsonValue, 1084 nlohmann::json{ 1085 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1086 {"MessageId", "Base.1.4.0.PropertyUnknown"}, 1087 {"Message", 1088 "The property " + arg1 + 1089 " is not in the list of valid properties for the resource."}, 1090 {"MessageArgs", {arg1}}, 1091 {"Severity", "Warning"}, 1092 {"Resolution", 1093 "Remove the unknown property from the request body and resubmit " 1094 "the request if the operation failed."}}, 1095 arg1); 1096 } 1097 1098 /** 1099 * @internal 1100 * @brief Formats NoValidSession message into JSON 1101 * 1102 * See header file for more information 1103 * @endinternal 1104 */ 1105 void noValidSession(crow::Response& res) 1106 { 1107 res.result(boost::beast::http::status::forbidden); 1108 addMessageToErrorJson( 1109 res.jsonValue, 1110 nlohmann::json{ 1111 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1112 {"MessageId", "Base.1.4.0.NoValidSession"}, 1113 {"Message", 1114 "There is no valid session established with the implementation."}, 1115 {"MessageArgs", nlohmann::json::array()}, 1116 {"Severity", "Critical"}, 1117 {"Resolution", 1118 "Establish as session before attempting any operations."}}); 1119 } 1120 1121 /** 1122 * @internal 1123 * @brief Formats InvalidObject message into JSON 1124 * 1125 * See header file for more information 1126 * @endinternal 1127 */ 1128 void invalidObject(crow::Response& res, const std::string& arg1) 1129 { 1130 res.result(boost::beast::http::status::bad_request); 1131 addMessageToErrorJson( 1132 res.jsonValue, 1133 nlohmann::json{ 1134 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1135 {"MessageId", "Base.1.4.0.InvalidObject"}, 1136 {"Message", "The object at " + arg1 + " is invalid."}, 1137 {"MessageArgs", {arg1}}, 1138 {"Severity", "Critical"}, 1139 {"Resolution", 1140 "Either the object is malformed or the URI is not correct. " 1141 "Correct the condition and resubmit the request if it failed."}}); 1142 } 1143 1144 /** 1145 * @internal 1146 * @brief Formats ResourceInStandby message into JSON 1147 * 1148 * See header file for more information 1149 * @endinternal 1150 */ 1151 void resourceInStandby(crow::Response& res) 1152 { 1153 res.result(boost::beast::http::status::service_unavailable); 1154 addMessageToErrorJson( 1155 res.jsonValue, 1156 nlohmann::json{ 1157 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1158 {"MessageId", "Base.1.4.0.ResourceInStandby"}, 1159 {"Message", "The request could not be performed because the " 1160 "resource is in standby."}, 1161 {"MessageArgs", nlohmann::json::array()}, 1162 {"Severity", "Critical"}, 1163 {"Resolution", "Ensure that the resource is in the correct power " 1164 "state and resubmit the request."}}); 1165 } 1166 1167 /** 1168 * @internal 1169 * @brief Formats ActionParameterValueTypeError message into JSON 1170 * 1171 * See header file for more information 1172 * @endinternal 1173 */ 1174 void actionParameterValueTypeError(crow::Response& res, const std::string& arg1, 1175 const std::string& arg2, 1176 const std::string& arg3) 1177 { 1178 res.result(boost::beast::http::status::bad_request); 1179 addMessageToErrorJson( 1180 res.jsonValue, 1181 nlohmann::json{ 1182 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1183 {"MessageId", "Base.1.4.0.ActionParameterValueTypeError"}, 1184 {"Message", 1185 "The value " + arg1 + " for the parameter " + arg2 + 1186 " in the action " + arg3 + 1187 " is of a different type than the parameter can accept."}, 1188 {"MessageArgs", {arg1, arg2, arg3}}, 1189 {"Severity", "Warning"}, 1190 {"Resolution", 1191 "Correct the value for the parameter in the request body and " 1192 "resubmit the request if the operation failed."}}); 1193 } 1194 1195 /** 1196 * @internal 1197 * @brief Formats SessionLimitExceeded message into JSON 1198 * 1199 * See header file for more information 1200 * @endinternal 1201 */ 1202 void sessionLimitExceeded(crow::Response& res) 1203 { 1204 res.result(boost::beast::http::status::service_unavailable); 1205 addMessageToErrorJson( 1206 res.jsonValue, 1207 nlohmann::json{ 1208 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1209 {"MessageId", "Base.1.4.0.SessionLimitExceeded"}, 1210 {"Message", "The session establishment failed due to the number of " 1211 "simultaneous sessions exceeding the limit of the " 1212 "implementation."}, 1213 {"MessageArgs", nlohmann::json::array()}, 1214 {"Severity", "Critical"}, 1215 {"Resolution", "Reduce the number of other sessions before trying " 1216 "to establish the session or increase the limit of " 1217 "simultaneous sessions (if supported)."}}); 1218 } 1219 1220 /** 1221 * @internal 1222 * @brief Formats ActionNotSupported message into JSON 1223 * 1224 * See header file for more information 1225 * @endinternal 1226 */ 1227 void actionNotSupported(crow::Response& res, const std::string& arg1) 1228 { 1229 res.result(boost::beast::http::status::bad_request); 1230 addMessageToErrorJson( 1231 res.jsonValue, 1232 nlohmann::json{ 1233 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1234 {"MessageId", "Base.1.4.0.ActionNotSupported"}, 1235 {"Message", 1236 "The action " + arg1 + " is not supported by the resource."}, 1237 {"MessageArgs", {arg1}}, 1238 {"Severity", "Critical"}, 1239 {"Resolution", 1240 "The action supplied cannot be resubmitted to the implementation. " 1241 " Perhaps the action was invalid, the wrong resource was the " 1242 "target or the implementation documentation may be of " 1243 "assistance."}}); 1244 } 1245 1246 /** 1247 * @internal 1248 * @brief Formats InvalidIndex message into JSON 1249 * 1250 * See header file for more information 1251 * @endinternal 1252 */ 1253 void invalidIndex(crow::Response& res, const int& arg1) 1254 { 1255 res.result(boost::beast::http::status::bad_request); 1256 addMessageToErrorJson( 1257 res.jsonValue, 1258 nlohmann::json{ 1259 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1260 {"MessageId", "Base.1.4.0.InvalidIndex"}, 1261 {"Message", "The index " + std::to_string(arg1) + 1262 " is not a valid offset into the array."}, 1263 {"MessageArgs", {std::to_string(arg1)}}, 1264 {"Severity", "Warning"}, 1265 {"Resolution", "Verify the index value provided is within the " 1266 "bounds of the array."}}); 1267 } 1268 1269 /** 1270 * @internal 1271 * @brief Formats EmptyJSON message into JSON 1272 * 1273 * See header file for more information 1274 * @endinternal 1275 */ 1276 void emptyJSON(crow::Response& res) 1277 { 1278 res.result(boost::beast::http::status::bad_request); 1279 addMessageToErrorJson( 1280 res.jsonValue, 1281 nlohmann::json{ 1282 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1283 {"MessageId", "Base.1.4.0.EmptyJSON"}, 1284 {"Message", "The request body submitted contained an empty JSON " 1285 "object and the service is unable to process it."}, 1286 {"MessageArgs", nlohmann::json::array()}, 1287 {"Severity", "Warning"}, 1288 {"Resolution", 1289 "Add properties in the JSON object and resubmit the request."}}); 1290 } 1291 1292 /** 1293 * @internal 1294 * @brief Formats QueryNotSupportedOnResource message into JSON 1295 * 1296 * See header file for more information 1297 * @endinternal 1298 */ 1299 void queryNotSupportedOnResource(crow::Response& res) 1300 { 1301 res.result(boost::beast::http::status::forbidden); 1302 addMessageToErrorJson( 1303 res.jsonValue, 1304 nlohmann::json{ 1305 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1306 {"MessageId", "Base.1.4.0.QueryNotSupportedOnResource"}, 1307 {"Message", "Querying is not supported on the requested resource."}, 1308 {"MessageArgs", nlohmann::json::array()}, 1309 {"Severity", "Warning"}, 1310 {"Resolution", "Remove the query parameters and resubmit the " 1311 "request if the operation failed."}}); 1312 } 1313 1314 /** 1315 * @internal 1316 * @brief Formats InsufficientPrivilege message into JSON 1317 * 1318 * See header file for more information 1319 * @endinternal 1320 */ 1321 void insufficientPrivilege(crow::Response& res) 1322 { 1323 res.result(boost::beast::http::status::forbidden); 1324 addMessageToErrorJson( 1325 res.jsonValue, 1326 nlohmann::json{ 1327 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1328 {"MessageId", "Base.1.4.0.InsufficientPrivilege"}, 1329 {"Message", "There are insufficient privileges for the account or " 1330 "credentials associated with the current session to " 1331 "perform the requested operation."}, 1332 {"MessageArgs", nlohmann::json::array()}, 1333 {"Severity", "Critical"}, 1334 {"Resolution", 1335 "Either abandon the operation or change the associated access " 1336 "rights and resubmit the request if the operation failed."}}); 1337 } 1338 1339 /** 1340 * @internal 1341 * @brief Formats PropertyValueModified message into JSON 1342 * 1343 * See header file for more information 1344 * @endinternal 1345 */ 1346 void propertyValueModified(crow::Response& res, const std::string& arg1, 1347 const std::string& arg2) 1348 { 1349 res.result(boost::beast::http::status::ok); 1350 addMessageToJson( 1351 res.jsonValue, 1352 nlohmann::json{ 1353 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1354 {"MessageId", "Base.1.4.0.PropertyValueModified"}, 1355 {"Message", "The property " + arg1 + " was assigned the value " + 1356 arg2 + " due to modification by the service."}, 1357 {"MessageArgs", {arg1, arg2}}, 1358 {"Severity", "Warning"}, 1359 {"Resolution", "No resolution is required."}}, 1360 arg1); 1361 } 1362 1363 /** 1364 * @internal 1365 * @brief Formats AccountNotModified message into JSON 1366 * 1367 * See header file for more information 1368 * @endinternal 1369 */ 1370 void accountNotModified(crow::Response& res) 1371 { 1372 res.result(boost::beast::http::status::bad_request); 1373 addMessageToErrorJson( 1374 res.jsonValue, 1375 nlohmann::json{ 1376 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1377 {"MessageId", "Base.1.4.0.AccountNotModified"}, 1378 {"Message", "The account modification request failed."}, 1379 {"MessageArgs", nlohmann::json::array()}, 1380 {"Severity", "Warning"}, 1381 {"Resolution", "The modification may have failed due to permission " 1382 "issues or issues with the request body."}}); 1383 } 1384 1385 /** 1386 * @internal 1387 * @brief Formats QueryParameterValueFormatError message into JSON 1388 * 1389 * See header file for more information 1390 * @endinternal 1391 */ 1392 void queryParameterValueFormatError(crow::Response& res, 1393 const std::string& arg1, 1394 const std::string& arg2) 1395 { 1396 res.result(boost::beast::http::status::bad_request); 1397 addMessageToErrorJson( 1398 res.jsonValue, 1399 nlohmann::json{ 1400 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1401 {"MessageId", "Base.1.4.0.QueryParameterValueFormatError"}, 1402 {"Message", 1403 "The value " + arg1 + " for the parameter " + arg2 + 1404 " is of a different format than the parameter can accept."}, 1405 {"MessageArgs", {arg1, arg2}}, 1406 {"Severity", "Warning"}, 1407 {"Resolution", 1408 "Correct the value for the query parameter in the request and " 1409 "resubmit the request if the operation failed."}}); 1410 } 1411 1412 /** 1413 * @internal 1414 * @brief Formats PropertyMissing message into JSON for the specified property 1415 * 1416 * See header file for more information 1417 * @endinternal 1418 */ 1419 void propertyMissing(crow::Response& res, const std::string& arg1) 1420 { 1421 res.result(boost::beast::http::status::bad_request); 1422 addMessageToJson( 1423 res.jsonValue, 1424 nlohmann::json{ 1425 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1426 {"MessageId", "Base.1.4.0.PropertyMissing"}, 1427 {"Message", "The property " + arg1 + 1428 " is a required property and must be included in " 1429 "the request."}, 1430 {"MessageArgs", {arg1}}, 1431 {"Severity", "Warning"}, 1432 {"Resolution", 1433 "Ensure that the property is in the request body and has a valid " 1434 "value and resubmit the request if the operation failed."}}, 1435 arg1); 1436 } 1437 1438 /** 1439 * @internal 1440 * @brief Formats ResourceExhaustion message into JSON 1441 * 1442 * See header file for more information 1443 * @endinternal 1444 */ 1445 void resourceExhaustion(crow::Response& res, const std::string& arg1) 1446 { 1447 res.result(boost::beast::http::status::service_unavailable); 1448 addMessageToErrorJson( 1449 res.jsonValue, 1450 nlohmann::json{ 1451 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1452 {"MessageId", "Base.1.4.0.ResourceExhaustion"}, 1453 {"Message", "The resource " + arg1 + 1454 " was unable to satisfy the request due to " 1455 "unavailability of resources."}, 1456 {"MessageArgs", {arg1}}, 1457 {"Severity", "Critical"}, 1458 {"Resolution", "Ensure that the resources are available and " 1459 "resubmit the request."}}); 1460 } 1461 1462 /** 1463 * @internal 1464 * @brief Formats AccountModified message into JSON 1465 * 1466 * See header file for more information 1467 * @endinternal 1468 */ 1469 void accountModified(crow::Response& res) 1470 { 1471 res.result(boost::beast::http::status::ok); 1472 addMessageToErrorJson( 1473 res.jsonValue, 1474 nlohmann::json{ 1475 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1476 {"MessageId", "Base.1.4.0.AccountModified"}, 1477 {"Message", "The account was successfully modified."}, 1478 {"MessageArgs", nlohmann::json::array()}, 1479 {"Severity", "OK"}, 1480 {"Resolution", "No resolution is required."}}); 1481 } 1482 1483 /** 1484 * @internal 1485 * @brief Formats QueryParameterOutOfRange message into JSON 1486 * 1487 * See header file for more information 1488 * @endinternal 1489 */ 1490 void queryParameterOutOfRange(crow::Response& res, const std::string& arg1, 1491 const std::string& arg2, const std::string& arg3) 1492 { 1493 res.result(boost::beast::http::status::bad_request); 1494 addMessageToErrorJson( 1495 res.jsonValue, 1496 nlohmann::json{ 1497 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1498 {"MessageId", "Base.1.4.0.QueryParameterOutOfRange"}, 1499 {"Message", "The value " + arg1 + " for the query parameter " + 1500 arg2 + " is out of range " + arg3 + "."}, 1501 {"MessageArgs", {arg1, arg2, arg3}}, 1502 {"Severity", "Warning"}, 1503 {"Resolution", 1504 "Reduce the value for the query parameter to a value that is " 1505 "within range, such as a start or count value that is within " 1506 "bounds of the number of resources in a collection or a page that " 1507 "is within the range of valid pages."}}); 1508 } 1509 1510 } // namespace messages 1511 1512 } // namespace redfish 1513