run_pyl
This commit is contained in:
parent
443a855782
commit
c270ababd9
|
@ -1,7 +1,7 @@
|
|||
"""__init__."""
|
||||
import faulthandler
|
||||
import os
|
||||
import sys
|
||||
import faulthandler
|
||||
from typing import Any
|
||||
|
||||
import connexion # type: ignore
|
||||
|
|
|
@ -7,7 +7,6 @@ import sentry_sdk
|
|||
from flask import current_app
|
||||
from flask import g
|
||||
|
||||
from spiffworkflow_backend.exceptions.api_error import ApiError
|
||||
from spiffworkflow_backend.services.file_system_service import FileSystemService
|
||||
from spiffworkflow_backend.services.secret_service import SecretService
|
||||
from spiffworkflow_backend.services.user_service import UserService
|
||||
|
@ -47,23 +46,44 @@ class ServiceTaskDelegate:
|
|||
@staticmethod
|
||||
def get_message_for_status(code):
|
||||
"""Given a code like 404, return a string like 'The requested resource was not found.'"""
|
||||
msg = f'HTTP Status Code {code}.'
|
||||
msg = f"HTTP Status Code {code}."
|
||||
if code == 301:
|
||||
msg = '301 (Permanent Redirect) - you may need to use a different URL in this service task.'
|
||||
msg = (
|
||||
"301 (Permanent Redirect) - you may need to use a different URL in this"
|
||||
" service task."
|
||||
)
|
||||
if code == 302:
|
||||
msg = '302 (Temporary Redirect) - you may need to use a different URL in this service task.'
|
||||
msg = (
|
||||
"302 (Temporary Redirect) - you may need to use a different URL in this"
|
||||
" service task."
|
||||
)
|
||||
if code == 400:
|
||||
msg = '400 (Bad Request) - The request was received by the service, but it was not understood.'
|
||||
msg = (
|
||||
"400 (Bad Request) - The request was received by the service, but it"
|
||||
" was not understood."
|
||||
)
|
||||
if code == 401:
|
||||
msg = '401 (Unauthorized Error) - this end point requires some form of authentication.'
|
||||
msg = (
|
||||
"401 (Unauthorized Error) - this end point requires some form of"
|
||||
" authentication."
|
||||
)
|
||||
if code == 403:
|
||||
msg = '403 (Forbidden) - The service you called refused to accept the request.'
|
||||
msg = (
|
||||
"403 (Forbidden) - The service you called refused to accept the"
|
||||
" request."
|
||||
)
|
||||
if code == 404:
|
||||
msg = '404 (Not Found) - The service did not find the requested resource.'
|
||||
msg = "404 (Not Found) - The service did not find the requested resource."
|
||||
if code == 500:
|
||||
msg = '500 (Internal Server Error) - The service you called is experiencing technical difficulties.'
|
||||
msg = (
|
||||
"500 (Internal Server Error) - The service you called is experiencing"
|
||||
" technical difficulties."
|
||||
)
|
||||
if code == 501:
|
||||
msg = '501 (Not Implemented) - This service needs to be called with the different method (like POST not GET).'
|
||||
msg = (
|
||||
"501 (Not Implemented) - This service needs to be called with the"
|
||||
" different method (like POST not GET)."
|
||||
)
|
||||
return msg
|
||||
|
||||
@staticmethod
|
||||
|
@ -91,15 +111,22 @@ class ServiceTaskDelegate:
|
|||
|
||||
if proxied_response.status_code >= 300:
|
||||
error = f"Received an unexpected response from the service : "
|
||||
error += ServiceTaskDelegate.get_message_for_status(proxied_response.status_code)
|
||||
error += ServiceTaskDelegate.get_message_for_status(
|
||||
proxied_response.status_code
|
||||
)
|
||||
if "error" in parsed_response:
|
||||
error += parsed_response["error"]
|
||||
if json_parse_error:
|
||||
error += "A critical component (The connector proxy) is not responding correctly."
|
||||
error += (
|
||||
"A critical component (The connector proxy) is not responding"
|
||||
" correctly."
|
||||
)
|
||||
raise ConnectorProxyError(error)
|
||||
elif json_parse_error:
|
||||
raise ConnectorProxyError( f"There is a problem with this connector: '{name}'. "
|
||||
f"Responses for connectors must be in JSON format. ")
|
||||
raise ConnectorProxyError(
|
||||
f"There is a problem with this connector: '{name}'. "
|
||||
"Responses for connectors must be in JSON format. "
|
||||
)
|
||||
|
||||
if "refreshed_token_set" not in parsed_response:
|
||||
return response_text
|
||||
|
@ -111,7 +138,6 @@ class ServiceTaskDelegate:
|
|||
return json.dumps(parsed_response["api_response"])
|
||||
|
||||
|
||||
|
||||
class ServiceTaskService:
|
||||
"""ServiceTaskService."""
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@ from flask.app import Flask
|
|||
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
|
||||
|
||||
from spiffworkflow_backend.services.secret_service import SecretService
|
||||
from spiffworkflow_backend.services.service_task_service import ServiceTaskDelegate, ConnectorProxyError
|
||||
from spiffworkflow_backend.services.service_task_service import ConnectorProxyError
|
||||
from spiffworkflow_backend.services.service_task_service import ServiceTaskDelegate
|
||||
|
||||
|
||||
class TestServiceTaskDelegate(BaseTest):
|
||||
|
@ -37,7 +38,10 @@ class TestServiceTaskDelegate(BaseTest):
|
|||
self, app: Flask, with_db_and_bpmn_file_cleanup: None
|
||||
) -> None:
|
||||
with pytest.raises(ConnectorProxyError) as ae:
|
||||
ServiceTaskDelegate.call_connector('my_invalid_operation', {}, {})
|
||||
ServiceTaskDelegate.call_connector("my_invalid_operation", {}, {})
|
||||
assert "404" in str(ae)
|
||||
assert "The service did not find the requested resource." in str(ae)
|
||||
assert "A critical component (The connector proxy) is not responding correctly." in str(ae)
|
||||
assert (
|
||||
"A critical component (The connector proxy) is not responding correctly."
|
||||
in str(ae)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue