| 1635 | } |
| 1636 | |
| 1637 | void RenderingController::HandleGET_mxnWindows(const httplib::Request& req, httplib::Response& res) const |
| 1638 | { |
| 1639 | if (m_RenderWindowBridge == nullptr || !m_RenderWindowBridge->HasMxNWindowListProvider()) |
| 1640 | { |
| 1641 | const auto error = ErrorResponse::RenderWindowNotAvailable(req.path); |
| 1642 | this->SendErrorResponse(res, 503, error); |
| 1643 | return; |
| 1644 | } |
| 1645 | |
| 1646 | std::vector<MxNWindowInfo> windows; |
| 1647 | try |
| 1648 | { |
| 1649 | windows = m_RenderWindowBridge->ListMxNWindows(); |
| 1650 | } |
| 1651 | catch (const mitk::Exception& e) |
| 1652 | { |
| 1653 | // mitk::Exception from the bridge layer signals a binding-contract |
| 1654 | // violation surfaced via mitkThrow (e.g. an unparseable v2 |
| 1655 | // view_direction, or a 2D MxN cell with no plane set when |
| 1656 | // MxNWindowInfoToWindowsListJson materialises the response). Map to |
| 1657 | // 422 RENDERING_ERROR -- the request shape was valid; the rendering |
| 1658 | // backend reports an unrecoverable state. The generic |
| 1659 | // MapBridgeException below would otherwise emit 500 INTERNAL_ERROR, |
| 1660 | // which is the wrong status class for a downstream contract failure. |
| 1661 | const auto error = ErrorResponse::RenderingError(e.what(), req.path); |
| 1662 | this->SendErrorResponse(res, 422, error); |
| 1663 | return; |
| 1664 | } |
| 1665 | catch (const std::exception& e) |
| 1666 | { |
| 1667 | const auto [status, payload] = MapBridgeException(e, req.path); |
| 1668 | this->SendErrorResponse(res, status, payload); |
| 1669 | return; |
| 1670 | } |
| 1671 | |
| 1672 | res.status = 200; |
| 1673 | res.set_content(MxNWindowInfoToWindowsListJson(windows).dump(), "application/json"); |
| 1674 | } |
| 1675 | |
| 1676 | void RenderingController::HandleGET_mxnWindow(const httplib::Request& req, httplib::Response& res) const |
| 1677 | { |