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 // don't set res.result here because success is the default and any error 1017 // should overwrite the default 1018 addMessageToJsonRoot( 1019 res.jsonValue, 1020 nlohmann::json{ 1021 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1022 {"MessageId", "Base.1.4.0.Success"}, 1023 {"Message", "Successfully Completed Request"}, 1024 {"MessageArgs", nlohmann::json::array()}, 1025 {"Severity", "OK"}, 1026 {"Resolution", "None"}}); 1027 } 1028 1029 /** 1030 * @internal 1031 * @brief Formats Created message into JSON 1032 * 1033 * See header file for more information 1034 * @endinternal 1035 */ 1036 void created(crow::Response& res) 1037 { 1038 res.result(boost::beast::http::status::created); 1039 addMessageToJsonRoot( 1040 res.jsonValue, 1041 nlohmann::json{ 1042 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1043 {"MessageId", "Base.1.4.0.Created"}, 1044 {"Message", "The resource has been created successfully"}, 1045 {"MessageArgs", nlohmann::json::array()}, 1046 {"Severity", "OK"}, 1047 {"Resolution", "None"}}); 1048 } 1049 1050 /** 1051 * @internal 1052 * @brief Formats NoOperation message into JSON 1053 * 1054 * See header file for more information 1055 * @endinternal 1056 */ 1057 void noOperation(crow::Response& res) 1058 { 1059 res.result(boost::beast::http::status::bad_request); 1060 addMessageToErrorJson( 1061 res.jsonValue, 1062 nlohmann::json{ 1063 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1064 {"MessageId", "Base.1.4.0.NoOperation"}, 1065 {"Message", "The request body submitted contain no data to act " 1066 "upon and no changes to the resource took place."}, 1067 {"MessageArgs", nlohmann::json::array()}, 1068 {"Severity", "Warning"}, 1069 {"Resolution", 1070 "Add properties in the JSON object and resubmit the request."}}); 1071 } 1072 1073 /** 1074 * @internal 1075 * @brief Formats PropertyUnknown message into JSON for the specified property 1076 * 1077 * See header file for more information 1078 * @endinternal 1079 */ 1080 void propertyUnknown(crow::Response& res, const std::string& arg1) 1081 { 1082 res.result(boost::beast::http::status::bad_request); 1083 addMessageToJson( 1084 res.jsonValue, 1085 nlohmann::json{ 1086 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1087 {"MessageId", "Base.1.4.0.PropertyUnknown"}, 1088 {"Message", 1089 "The property " + arg1 + 1090 " is not in the list of valid properties for the resource."}, 1091 {"MessageArgs", {arg1}}, 1092 {"Severity", "Warning"}, 1093 {"Resolution", 1094 "Remove the unknown property from the request body and resubmit " 1095 "the request if the operation failed."}}, 1096 arg1); 1097 } 1098 1099 /** 1100 * @internal 1101 * @brief Formats NoValidSession message into JSON 1102 * 1103 * See header file for more information 1104 * @endinternal 1105 */ 1106 void noValidSession(crow::Response& res) 1107 { 1108 res.result(boost::beast::http::status::forbidden); 1109 addMessageToErrorJson( 1110 res.jsonValue, 1111 nlohmann::json{ 1112 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1113 {"MessageId", "Base.1.4.0.NoValidSession"}, 1114 {"Message", 1115 "There is no valid session established with the implementation."}, 1116 {"MessageArgs", nlohmann::json::array()}, 1117 {"Severity", "Critical"}, 1118 {"Resolution", 1119 "Establish as session before attempting any operations."}}); 1120 } 1121 1122 /** 1123 * @internal 1124 * @brief Formats InvalidObject message into JSON 1125 * 1126 * See header file for more information 1127 * @endinternal 1128 */ 1129 void invalidObject(crow::Response& res, const std::string& arg1) 1130 { 1131 res.result(boost::beast::http::status::bad_request); 1132 addMessageToErrorJson( 1133 res.jsonValue, 1134 nlohmann::json{ 1135 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1136 {"MessageId", "Base.1.4.0.InvalidObject"}, 1137 {"Message", "The object at " + arg1 + " is invalid."}, 1138 {"MessageArgs", {arg1}}, 1139 {"Severity", "Critical"}, 1140 {"Resolution", 1141 "Either the object is malformed or the URI is not correct. " 1142 "Correct the condition and resubmit the request if it failed."}}); 1143 } 1144 1145 /** 1146 * @internal 1147 * @brief Formats ResourceInStandby message into JSON 1148 * 1149 * See header file for more information 1150 * @endinternal 1151 */ 1152 void resourceInStandby(crow::Response& res) 1153 { 1154 res.result(boost::beast::http::status::service_unavailable); 1155 addMessageToErrorJson( 1156 res.jsonValue, 1157 nlohmann::json{ 1158 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1159 {"MessageId", "Base.1.4.0.ResourceInStandby"}, 1160 {"Message", "The request could not be performed because the " 1161 "resource is in standby."}, 1162 {"MessageArgs", nlohmann::json::array()}, 1163 {"Severity", "Critical"}, 1164 {"Resolution", "Ensure that the resource is in the correct power " 1165 "state and resubmit the request."}}); 1166 } 1167 1168 /** 1169 * @internal 1170 * @brief Formats ActionParameterValueTypeError message into JSON 1171 * 1172 * See header file for more information 1173 * @endinternal 1174 */ 1175 void actionParameterValueTypeError(crow::Response& res, const std::string& arg1, 1176 const std::string& arg2, 1177 const std::string& arg3) 1178 { 1179 res.result(boost::beast::http::status::bad_request); 1180 addMessageToErrorJson( 1181 res.jsonValue, 1182 nlohmann::json{ 1183 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1184 {"MessageId", "Base.1.4.0.ActionParameterValueTypeError"}, 1185 {"Message", 1186 "The value " + arg1 + " for the parameter " + arg2 + 1187 " in the action " + arg3 + 1188 " is of a different type than the parameter can accept."}, 1189 {"MessageArgs", {arg1, arg2, arg3}}, 1190 {"Severity", "Warning"}, 1191 {"Resolution", 1192 "Correct the value for the parameter in the request body and " 1193 "resubmit the request if the operation failed."}}); 1194 } 1195 1196 /** 1197 * @internal 1198 * @brief Formats SessionLimitExceeded message into JSON 1199 * 1200 * See header file for more information 1201 * @endinternal 1202 */ 1203 void sessionLimitExceeded(crow::Response& res) 1204 { 1205 res.result(boost::beast::http::status::service_unavailable); 1206 addMessageToErrorJson( 1207 res.jsonValue, 1208 nlohmann::json{ 1209 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1210 {"MessageId", "Base.1.4.0.SessionLimitExceeded"}, 1211 {"Message", "The session establishment failed due to the number of " 1212 "simultaneous sessions exceeding the limit of the " 1213 "implementation."}, 1214 {"MessageArgs", nlohmann::json::array()}, 1215 {"Severity", "Critical"}, 1216 {"Resolution", "Reduce the number of other sessions before trying " 1217 "to establish the session or increase the limit of " 1218 "simultaneous sessions (if supported)."}}); 1219 } 1220 1221 /** 1222 * @internal 1223 * @brief Formats ActionNotSupported message into JSON 1224 * 1225 * See header file for more information 1226 * @endinternal 1227 */ 1228 void actionNotSupported(crow::Response& res, const std::string& arg1) 1229 { 1230 res.result(boost::beast::http::status::bad_request); 1231 addMessageToErrorJson( 1232 res.jsonValue, 1233 nlohmann::json{ 1234 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1235 {"MessageId", "Base.1.4.0.ActionNotSupported"}, 1236 {"Message", 1237 "The action " + arg1 + " is not supported by the resource."}, 1238 {"MessageArgs", {arg1}}, 1239 {"Severity", "Critical"}, 1240 {"Resolution", 1241 "The action supplied cannot be resubmitted to the implementation. " 1242 " Perhaps the action was invalid, the wrong resource was the " 1243 "target or the implementation documentation may be of " 1244 "assistance."}}); 1245 } 1246 1247 /** 1248 * @internal 1249 * @brief Formats InvalidIndex message into JSON 1250 * 1251 * See header file for more information 1252 * @endinternal 1253 */ 1254 void invalidIndex(crow::Response& res, const int& arg1) 1255 { 1256 res.result(boost::beast::http::status::bad_request); 1257 addMessageToErrorJson( 1258 res.jsonValue, 1259 nlohmann::json{ 1260 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1261 {"MessageId", "Base.1.4.0.InvalidIndex"}, 1262 {"Message", "The index " + std::to_string(arg1) + 1263 " is not a valid offset into the array."}, 1264 {"MessageArgs", {std::to_string(arg1)}}, 1265 {"Severity", "Warning"}, 1266 {"Resolution", "Verify the index value provided is within the " 1267 "bounds of the array."}}); 1268 } 1269 1270 /** 1271 * @internal 1272 * @brief Formats EmptyJSON message into JSON 1273 * 1274 * See header file for more information 1275 * @endinternal 1276 */ 1277 void emptyJSON(crow::Response& res) 1278 { 1279 res.result(boost::beast::http::status::bad_request); 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.EmptyJSON"}, 1285 {"Message", "The request body submitted contained an empty JSON " 1286 "object and the service is unable to process it."}, 1287 {"MessageArgs", nlohmann::json::array()}, 1288 {"Severity", "Warning"}, 1289 {"Resolution", 1290 "Add properties in the JSON object and resubmit the request."}}); 1291 } 1292 1293 /** 1294 * @internal 1295 * @brief Formats QueryNotSupportedOnResource message into JSON 1296 * 1297 * See header file for more information 1298 * @endinternal 1299 */ 1300 void queryNotSupportedOnResource(crow::Response& res) 1301 { 1302 res.result(boost::beast::http::status::forbidden); 1303 addMessageToErrorJson( 1304 res.jsonValue, 1305 nlohmann::json{ 1306 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1307 {"MessageId", "Base.1.4.0.QueryNotSupportedOnResource"}, 1308 {"Message", "Querying is not supported on the requested resource."}, 1309 {"MessageArgs", nlohmann::json::array()}, 1310 {"Severity", "Warning"}, 1311 {"Resolution", "Remove the query parameters and resubmit the " 1312 "request if the operation failed."}}); 1313 } 1314 1315 /** 1316 * @internal 1317 * @brief Formats InsufficientPrivilege message into JSON 1318 * 1319 * See header file for more information 1320 * @endinternal 1321 */ 1322 void insufficientPrivilege(crow::Response& res) 1323 { 1324 res.result(boost::beast::http::status::forbidden); 1325 addMessageToErrorJson( 1326 res.jsonValue, 1327 nlohmann::json{ 1328 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1329 {"MessageId", "Base.1.4.0.InsufficientPrivilege"}, 1330 {"Message", "There are insufficient privileges for the account or " 1331 "credentials associated with the current session to " 1332 "perform the requested operation."}, 1333 {"MessageArgs", nlohmann::json::array()}, 1334 {"Severity", "Critical"}, 1335 {"Resolution", 1336 "Either abandon the operation or change the associated access " 1337 "rights and resubmit the request if the operation failed."}}); 1338 } 1339 1340 /** 1341 * @internal 1342 * @brief Formats PropertyValueModified message into JSON 1343 * 1344 * See header file for more information 1345 * @endinternal 1346 */ 1347 void propertyValueModified(crow::Response& res, const std::string& arg1, 1348 const std::string& arg2) 1349 { 1350 res.result(boost::beast::http::status::ok); 1351 addMessageToJson( 1352 res.jsonValue, 1353 nlohmann::json{ 1354 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1355 {"MessageId", "Base.1.4.0.PropertyValueModified"}, 1356 {"Message", "The property " + arg1 + " was assigned the value " + 1357 arg2 + " due to modification by the service."}, 1358 {"MessageArgs", {arg1, arg2}}, 1359 {"Severity", "Warning"}, 1360 {"Resolution", "No resolution is required."}}, 1361 arg1); 1362 } 1363 1364 /** 1365 * @internal 1366 * @brief Formats AccountNotModified message into JSON 1367 * 1368 * See header file for more information 1369 * @endinternal 1370 */ 1371 void accountNotModified(crow::Response& res) 1372 { 1373 res.result(boost::beast::http::status::bad_request); 1374 addMessageToErrorJson( 1375 res.jsonValue, 1376 nlohmann::json{ 1377 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1378 {"MessageId", "Base.1.4.0.AccountNotModified"}, 1379 {"Message", "The account modification request failed."}, 1380 {"MessageArgs", nlohmann::json::array()}, 1381 {"Severity", "Warning"}, 1382 {"Resolution", "The modification may have failed due to permission " 1383 "issues or issues with the request body."}}); 1384 } 1385 1386 /** 1387 * @internal 1388 * @brief Formats QueryParameterValueFormatError message into JSON 1389 * 1390 * See header file for more information 1391 * @endinternal 1392 */ 1393 void queryParameterValueFormatError(crow::Response& res, 1394 const std::string& arg1, 1395 const std::string& arg2) 1396 { 1397 res.result(boost::beast::http::status::bad_request); 1398 addMessageToErrorJson( 1399 res.jsonValue, 1400 nlohmann::json{ 1401 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1402 {"MessageId", "Base.1.4.0.QueryParameterValueFormatError"}, 1403 {"Message", 1404 "The value " + arg1 + " for the parameter " + arg2 + 1405 " is of a different format than the parameter can accept."}, 1406 {"MessageArgs", {arg1, arg2}}, 1407 {"Severity", "Warning"}, 1408 {"Resolution", 1409 "Correct the value for the query parameter in the request and " 1410 "resubmit the request if the operation failed."}}); 1411 } 1412 1413 /** 1414 * @internal 1415 * @brief Formats PropertyMissing message into JSON for the specified property 1416 * 1417 * See header file for more information 1418 * @endinternal 1419 */ 1420 void propertyMissing(crow::Response& res, const std::string& arg1) 1421 { 1422 res.result(boost::beast::http::status::bad_request); 1423 addMessageToJson( 1424 res.jsonValue, 1425 nlohmann::json{ 1426 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1427 {"MessageId", "Base.1.4.0.PropertyMissing"}, 1428 {"Message", "The property " + arg1 + 1429 " is a required property and must be included in " 1430 "the request."}, 1431 {"MessageArgs", {arg1}}, 1432 {"Severity", "Warning"}, 1433 {"Resolution", 1434 "Ensure that the property is in the request body and has a valid " 1435 "value and resubmit the request if the operation failed."}}, 1436 arg1); 1437 } 1438 1439 /** 1440 * @internal 1441 * @brief Formats ResourceExhaustion message into JSON 1442 * 1443 * See header file for more information 1444 * @endinternal 1445 */ 1446 void resourceExhaustion(crow::Response& res, const std::string& arg1) 1447 { 1448 res.result(boost::beast::http::status::service_unavailable); 1449 addMessageToErrorJson( 1450 res.jsonValue, 1451 nlohmann::json{ 1452 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1453 {"MessageId", "Base.1.4.0.ResourceExhaustion"}, 1454 {"Message", "The resource " + arg1 + 1455 " was unable to satisfy the request due to " 1456 "unavailability of resources."}, 1457 {"MessageArgs", {arg1}}, 1458 {"Severity", "Critical"}, 1459 {"Resolution", "Ensure that the resources are available and " 1460 "resubmit the request."}}); 1461 } 1462 1463 /** 1464 * @internal 1465 * @brief Formats AccountModified message into JSON 1466 * 1467 * See header file for more information 1468 * @endinternal 1469 */ 1470 void accountModified(crow::Response& res) 1471 { 1472 res.result(boost::beast::http::status::ok); 1473 addMessageToErrorJson( 1474 res.jsonValue, 1475 nlohmann::json{ 1476 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1477 {"MessageId", "Base.1.4.0.AccountModified"}, 1478 {"Message", "The account was successfully modified."}, 1479 {"MessageArgs", nlohmann::json::array()}, 1480 {"Severity", "OK"}, 1481 {"Resolution", "No resolution is required."}}); 1482 } 1483 1484 /** 1485 * @internal 1486 * @brief Formats QueryParameterOutOfRange message into JSON 1487 * 1488 * See header file for more information 1489 * @endinternal 1490 */ 1491 void queryParameterOutOfRange(crow::Response& res, const std::string& arg1, 1492 const std::string& arg2, const std::string& arg3) 1493 { 1494 res.result(boost::beast::http::status::bad_request); 1495 addMessageToErrorJson( 1496 res.jsonValue, 1497 nlohmann::json{ 1498 {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"}, 1499 {"MessageId", "Base.1.4.0.QueryParameterOutOfRange"}, 1500 {"Message", "The value " + arg1 + " for the query parameter " + 1501 arg2 + " is out of range " + arg3 + "."}, 1502 {"MessageArgs", {arg1, arg2, arg3}}, 1503 {"Severity", "Warning"}, 1504 {"Resolution", 1505 "Reduce the value for the query parameter to a value that is " 1506 "within range, such as a start or count value that is within " 1507 "bounds of the number of resources in a collection or a page that " 1508 "is within the range of valid pages."}}); 1509 } 1510 1511 } // namespace messages 1512 1513 } // namespace redfish 1514