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