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