Repository: packit/packit-service
Issue: Correctly propagate the error on TF submission

Sentry Issue: [PCKT-002-PACKIT-SERVICE-5TQ](https://red-hat-it.sentry.io/issues/4204824898/?referrer=github_integration)

```
{'test': "Only one of test type 'fmf', 'script' or 'sti' can be specified in 'test' field."}, {'test': {'fmf': {'url': 'https://github.com/kornys/strimzi-kafka-operator', 'path': '.', 'ref': 'fd576ccefb71fabdacf08b1e17e1f4b1e62d51c2'}, 'tmt': {'name': 'acceptance'}}, 'environments': [{'arch': 'x86_64', 'os': {'compose': 'Fedora-38'}, 'tmt': {'context': {'distro': 'fedora-38', 'arch': 'x86_64', 'trigger': 'commit'}}, 'variables': {'PACKIT_FULL_REPO_NAME': 'kornys/strimzi-kafka-operator', 'PACKIT_UPSTREAM_NAME': 'strimzi-kafka-operator', 'PACKIT_DOWNSTREAM_NAME': 'strimzi-kafka-operator', 'PACKIT_DOWNSTREAM_URL': 'https://src.fedoraproject.org/rpms/strimzi-kafka-operator.git', 'PACKIT_PACKAGE_NAME': 'strimzi-kafka-operator', 'PACKIT_COMMIT_SHA': 'fd576ccefb71fabdacf08b1e17e1f4b1e62d51c2', 'PACKIT_SOURCE_SHA': 'fd576ccefb71fabdacf08b1e17e1f4b1e62d51c2', 'PACKIT_TARGET_SHA': 'b01312cbbdd9610496fb44efc21a3180c9faba25', 'PACKIT_SOURCE_BRANCH': 'packit-test', 'PACKIT_TARGET_BRANCH': 'tft-integration', 'PACKIT_SOU...
```

@lbarcziova : The problem here is when setting the commit check about the TF error we try to trim a `dict` returned by TF.

Changed files:
packit_service/worker/helpers/testing_farm.py, tests/integration/test_listen_to_fedmsg.py

diff --git a/packit_service/worker/helpers/testing_farm.py b/packit_service/worker/helpers/testing_farm.py
index ad44880a..985ae511 100644
--- a/packit_service/worker/helpers/testing_farm.py
+++ b/packit_service/worker/helpers/testing_farm.py
@@ -1065,12 +1065,19 @@ class TestingFarmJobHelper(CoprBuildJobHelper):
         """
         # something went wrong
         if response.json() and "errors" in response.json():
-            msg = response.json()["errors"]
+            errors = response.json()["errors"]
             # specific case, unsupported arch
-            if nested_get(response.json(), "errors", "environments", "0", "arch"):
-                msg = response.json()["errors"]["environments"]["0"]["arch"]
+            if not (msg := nested_get(errors, "environments", "0", "arch")):
+                msg = "There was an error in the API request"
+            markdown_content = (
+                f"There was an error in the API request: {errors}\\n"
+                "For the details of the API request parameters, see "
+                "[the Testing Farm API definition]"
+                "(https://testing-farm.gitlab.io/api/#operation/requestsPost)"
+            )
         else:
-            msg = f"Failed to submit tests: {response.reason}."
+            msg = response.reason
+            markdown_content = None
             if not self.celery_task.is_last_try():
                 return self._retry_on_submit_failure(test_run, response.reason)
 
@@ -1078,8 +1085,9 @@ class TestingFarmJobHelper(CoprBuildJobHelper):
         logger.error(f"{msg}, {self._payload_without_token(payload)}")
         self.report_status_to_tests_for_test_target(
             state=BaseCommitStatus.failure,
-            description=msg,
+            description=f"Failed to submit tests: {msg}.",
             target=test_run.target,
+            markdown_content=markdown_content,
         )
         return TaskResults(success=False, details={"msg": msg})
 
diff --git a/tests/integration/test_listen_to_fedmsg.py b/tests/integration/test_listen_to_fedmsg.py
index 34b30b83..ef23ef33 100644
--- a/tests/integration/test_listen_to_fedmsg.py
+++ b/tests/integration/test_listen_to_fedmsg.py
@@ -1634,7 +1634,9 @@ def test_copr_build_end_failed_testing_farm(copr_build_end, copr_build_pr):
             status_code=400,
             ok=False,
             content=b'{"errors": "some error"}',
-            json={"errors": "some error"},
+            json={
+                "errors": {"settings": {"pipeline": {"timeout": "unexpected type str"}}}
+            },
         )
     )
 
@@ -1649,10 +1651,13 @@ def test_copr_build_end_failed_testing_farm(copr_build_end, copr_build_pr):
     ).once()
     flexmock(StatusReporter).should_receive("report").with_args(
         state=BaseCommitStatus.failure,
-        description="some error",
+        description="Failed to submit tests: There was an error in the API request.",
         check_names=EXPECTED_TESTING_FARM_CHECK_NAME,
         url="",
-        markdown_content=None,
+        markdown_content="There was an error in the API request: {'settings': {'pipeline': {"
+        "'timeout': 'unexpected type str'}}}\\nFor the details"
+        " of the API request parameters, see [the Testing Farm API definition]"
+        "(https://testing-farm.gitlab.io/api/#operation/requestsPost)",
         links_to_external_services=None,
         update_feedback_time=object,
     ).once()