-
Notifications
You must be signed in to change notification settings - Fork 31
fix(gateway): consistent parameter-config error surface (list vs get) and drop dead classify fallback #543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mfaferek93
wants to merge
3
commits into
main
Choose a base branch
from
fix/param-config-error-surface-541-542
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
454c739
fix(gateway): consistent parameter-config error surface and drop dead…
mfaferek93 c782a5b
fix(gateway): scope list unavailable_nodes to 503, home classifier in…
mfaferek93 a00898e
fix(gateway): keep answering nodes on partial config list, rank all-d…
mfaferek93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...2_medkit_gateway/include/ros2_medkit_gateway/core/http/parameter_error_classification.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright 2026 bburda | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "ros2_medkit_gateway/core/configuration/parameter_types.hpp" | ||
|
|
||
| namespace ros2_medkit_gateway { | ||
| namespace handlers { | ||
|
|
||
| /// HTTP status + SOVD error code for a failed parameter operation. | ||
| struct ParameterErrorClassification { | ||
| int status_code = 500; | ||
| std::string error_code; | ||
| }; | ||
|
|
||
| /// Map a failed `ParameterResult` to an HTTP status + SOVD error code from its | ||
| /// structured `error_code`. Every failure path on the shipped | ||
| /// `Ros2ParameterTransport` sets a structured code, so a failure that still | ||
| /// carries `ParameterErrorCode::NONE` is a gateway-side defect and maps to 500 | ||
| /// internal-error - it is never guessed from the free-form message text. | ||
| ParameterErrorClassification classify_parameter_error(const ParameterResult & result); | ||
|
|
||
| } // namespace handlers | ||
| } // namespace ros2_medkit_gateway |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/ros2_medkit_gateway/src/core/http/parameter_error_classification.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Copyright 2026 bburda | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "ros2_medkit_gateway/core/http/parameter_error_classification.hpp" | ||
|
|
||
| #include "ros2_medkit_gateway/core/http/error_codes.hpp" | ||
|
|
||
| namespace ros2_medkit_gateway { | ||
| namespace handlers { | ||
|
|
||
| namespace { | ||
|
|
||
| /// Map a structured `ParameterErrorCode` to an HTTP status + SOVD error code. | ||
| ParameterErrorClassification classify_error_code(ParameterErrorCode error_code) { | ||
| ParameterErrorClassification result; | ||
|
|
||
| switch (error_code) { | ||
| case ParameterErrorCode::NOT_FOUND: | ||
| case ParameterErrorCode::NO_DEFAULTS_CACHED: | ||
| result.status_code = 404; | ||
| result.error_code = ERR_RESOURCE_NOT_FOUND; | ||
| break; | ||
| case ParameterErrorCode::READ_ONLY: | ||
| result.status_code = 403; | ||
| result.error_code = ERR_X_MEDKIT_ROS2_PARAMETER_READ_ONLY; | ||
| break; | ||
| case ParameterErrorCode::SERVICE_UNAVAILABLE: | ||
| case ParameterErrorCode::TIMEOUT: | ||
| result.status_code = 503; | ||
| result.error_code = ERR_X_MEDKIT_ROS2_NODE_UNAVAILABLE; | ||
| break; | ||
| case ParameterErrorCode::TYPE_MISMATCH: | ||
| case ParameterErrorCode::INVALID_VALUE: | ||
| result.status_code = 400; | ||
| result.error_code = ERR_INVALID_PARAMETER; | ||
| break; | ||
| case ParameterErrorCode::NONE: | ||
| // A failed ParameterResult that still carries NONE cannot occur on the | ||
| // shipped transport (every failure path sets a structured code), so a | ||
| // NONE failure is a gateway-side defect: surface it as 500 internal-error. | ||
| // The removed legacy string-matching fallback was unreachable, and would | ||
| // have misrouted messages it did not recognise (e.g. "did not respond", | ||
| // "not currently set") to 400 invalid-request had it ever run. | ||
| result.status_code = 500; | ||
| result.error_code = ERR_INTERNAL_ERROR; | ||
| break; | ||
| case ParameterErrorCode::SHUT_DOWN: | ||
| case ParameterErrorCode::INTERNAL_ERROR: | ||
| default: | ||
| result.status_code = 500; | ||
| result.error_code = ERR_INTERNAL_ERROR; | ||
| break; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| ParameterErrorClassification classify_parameter_error(const ParameterResult & result) { | ||
| return classify_error_code(result.error_code); | ||
| } | ||
|
|
||
| } // namespace handlers | ||
| } // namespace ros2_medkit_gateway |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.