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