diff --git a/qiskit_transpiler_service/wrappers/base.py b/qiskit_transpiler_service/wrappers/base.py index ed0ff7b..502eae4 100644 --- a/qiskit_transpiler_service/wrappers/base.py +++ b/qiskit_transpiler_service/wrappers/base.py @@ -180,7 +180,7 @@ def _raise_transpiler_error_and_log(msg: str): def _get_error_msg_from_response(exc: requests.exceptions.HTTPError): - if exc.response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY.value: + try: resp = exc.response.json() detail = resp.get("detail") # Default message @@ -194,6 +194,8 @@ def _get_error_msg_from_response(exc: requests.exceptions.HTTPError): if detail_input and detail_msg: msg = f"Wrong input '{detail_input}'. {detail_msg}" - else: + except: + # If something fails decoding the error + # just show the incoming error msg = f"Internal error: {str(exc)}" return msg diff --git a/tests/test_transpiler_service.py b/tests/test_transpiler_service.py index 37a7c3b..73b4571 100644 --- a/tests/test_transpiler_service.py +++ b/tests/test_transpiler_service.py @@ -175,26 +175,6 @@ def test_transpile_non_valid_backend(): ) -def test_wrong_url(): - random_circ = random_circuit(5, depth=2, seed=42) - transpiler_service = TranspilerService( - backend_name="ibm_kyoto", - ai="false", - optimization_level=3, - ) - - transpiler_service.transpiler_service.url = "https://cloud-transpiler-experimental.quantum.ibm.com/INVALID" - - try: - transpiler_service.run(random_circ) - pytest.fail("Error expected") - except Exception as e: - assert ( - "Internal error: 404 Client Error: Not Found for url:" in - str(e) - ) - - def test_transpile_exceed_circuit_size(): circuit = EfficientSU2(120, entanglement="full", reps=5).decompose() transpiler_service = TranspilerService( @@ -259,8 +239,11 @@ def test_transpile_wrong_url(): transpiler_service.run(circuit) pytest.fail("Error expected") except Exception as e: - assert "Expecting value: line 1 column 1 (char 0)" in str(e) - assert type(e).__name__ == "JSONDecodeError" + assert ( + "Internal error: 404 Client Error: Not Found for url: https://www.ibm.com/transpile" + in str(e) + ) + assert type(e).__name__ == "TranspilerError" @pytest.mark.disable_monkeypatch