Requests: Add some more failure checks and improve response codes

This commit is contained in:
tt2468 2021-09-17 02:43:20 -07:00
parent eebcc25115
commit d811c95e10
4 changed files with 8 additions and 3 deletions

View File

@ -108,7 +108,7 @@ RequestResult RequestHandler::CreateSceneCollection(const Request& request)
bool success = false;
QMetaObject::invokeMethod(mainWindow, "AddSceneCollection", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, success), Q_ARG(bool, true), Q_ARG(QString, QString::fromStdString(sceneCollectionName)));
if (!success)
return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Failed to create the scene collection for an unknown reason");
return RequestResult::Error(RequestStatus::ResourceCreationFailed, "Failed to create the scene collection.");
return RequestResult::Success();
}
@ -349,7 +349,7 @@ RequestResult RequestHandler::SetStreamServiceSettings(const Request& request)
OBSService newStreamService = obs_service_create(requestedStreamServiceType.c_str(), "obs_websocket_custom_service", requestedStreamServiceSettings, NULL);
// TODO: Check service type here, instead of relying on service creation to fail.
if (!newStreamService)
return RequestResult::Error(RequestStatus::ResourceCreationFailed, "Creating the stream service with the requested streamServiceType failed. It may be an invalid type.");
return RequestResult::Error(RequestStatus::ResourceCreationFailed, "Failed to create the stream service with the requested streamServiceType. It may be an invalid type.");
obs_frontend_set_streaming_service(newStreamService);
}

View File

@ -76,7 +76,7 @@ RequestResult RequestHandler::CreateInput(const Request& request)
obs_sceneitem_t *sceneItem = Utils::Obs::ActionHelper::CreateInput(inputName, inputKind, inputSettings, scene, sceneItemEnabled);
if (!sceneItem)
return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Creation of the input or scene item failed.");
return RequestResult::Error(RequestStatus::ResourceCreationFailed, "Creation of the input or scene item failed.");
json responseData;
responseData["sceneItemId"] = obs_sceneitem_get_id(sceneItem);

View File

@ -50,6 +50,8 @@ RequestResult RequestHandler::CreateSceneItem(const Request& request)
sceneItemEnabled = request.RequestData["sceneItemEnabled"];
obs_sceneitem_t *sceneItem = Utils::Obs::ActionHelper::CreateSceneItem(source, scene, sceneItemEnabled);
if (!sceneItem)
return RequestResult::Error(RequestStatus::ResourceCreationFailed, "Failed to create the scene item.");
json responseData;
responseData["sceneItemId"] = obs_sceneitem_get_id(sceneItem);

View File

@ -81,6 +81,9 @@ RequestResult RequestHandler::CreateScene(const Request& request)
return RequestResult::Error(RequestStatus::ResourceAlreadyExists, "A source already exists by that scene name.");
obs_scene_t *createdScene = obs_scene_create(sceneName.c_str());
if (!createdScene)
return RequestResult::Error(RequestStatus::ResourceCreationFailed, "Failed to create the scene.");
obs_scene_release(createdScene);
return RequestResult::Success();