Skip to content

Commit

Permalink
Enhance GetWindowHandle API docs and error handling
Browse files Browse the repository at this point in the history
- Updated `SessionsController.cs` to improve API documentation and error handling for the `GetWindowHandle` method.
- Added Swagger documentation annotations for better clarity and understanding of the method's purpose, parameters, and possible responses.
- Included response annotations for HTTP status codes 200, 404, and 500, detailing the outcomes and return types.
- Modified the method signature to include a `[SwaggerParameter]` annotation for the `session` parameter, enhancing parameter documentation.
- Improved error handling and response preparation in the method's implementation for more robust operation.
  • Loading branch information
gravity-api committed Jul 14, 2024
1 parent e2b70f3 commit 88a6bfd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Uia.DriverServer/Controllers/SessionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,24 @@ public IActionResult GetStatus()
});
}

// GET wd/hub/session/{session}/window
// GET session/{session}/window
[HttpGet]
[Route("session/{session}/window")]
public IActionResult GetWindowHandle(string session)
[SwaggerOperation(
Summary = "Gets the handle of the currently focused window for the specified session.",
Description = "Retrieves the handle of the currently focused window for the session identified by the given session ID.",
Tags = ["Sessions"])]
[SwaggerResponse(200, "Window handle retrieved successfully.", typeof(string))]
[SwaggerResponse(404, "Session not found. The session ID provided does not exist.")]
[SwaggerResponse(500, "Internal server error. An error occurred while retrieving the window handle.")]
public IActionResult GetWindowHandle(
[SwaggerParameter(Description = "The unique identifier for the session.")][FromRoute] string session)
{
// Get the handle of the currently focused window
var (statusCode, handle) = _domain.SessionsRepository.GetHandle(session);

// Prepare the response based on the status code
var response = statusCode == StatusCodes.Status404NotFound
? new WebDriverResponseModel(session, new Dictionary<string, string> { ["error"] = "no such window" })
: new WebDriverResponseModel(session, value: handle);
Expand Down

0 comments on commit 88a6bfd

Please sign in to comment.