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