Commit 1e2d06a5 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

NBI component - TFS-API connector:

- Refactor gRPC error handling to return response directly in Resources.py and simplify test case in test_tfs_api_grpc_error_mapping.py
parent 294ec19e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -58,10 +58,10 @@ def _format_grpc_error(exc : grpc.RpcError):
    details = exc.details() if hasattr(exc, 'details') else str(exc)
    LOGGER.warning('Mapping gRPC error to HTTP status: grpc_status=%s http_status=%s details=%s',
                   grpc_status, http_status, details)
    return jsonify({
    return {
        'error': grpc_status.name if grpc_status is not None else 'UNKNOWN',
        'message': details,
    }), http_status
    }, http_status


class _Resource(Resource):
+2 −6
Original line number Diff line number Diff line
@@ -12,9 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import grpc
from flask import Flask
from nbi.service.tfs_api.Resources import _format_grpc_error
import grpc


class _FakeRpcError(grpc.RpcError):
@@ -31,10 +30,7 @@ class _FakeRpcError(grpc.RpcError):


def _mapped_error(code, details='mapped error'):
    app = Flask(__name__)
    with app.app_context():
        response, status = _format_grpc_error(_FakeRpcError(code, details))
        return response.get_json(), status
    return _format_grpc_error(_FakeRpcError(code, details))


def test_grpc_already_exists_maps_to_http_conflict():