Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions servc/svc/com/worker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,43 @@ def run_resolver(
self, method: RESOLVER, context: RESOLVER_CONTEXT, args: Tuple[str, Any]
) -> Tuple[StatusCode, ResponseArtifact | None]:
id, payload = args
statuscode: StatusCode = StatusCode.OK
response: ResponseArtifact | None = None
error: Any = None

try:
response = method(id, payload, context)
return StatusCode.OK, getAnswerArtifact(id, response)
response = getAnswerArtifact(id, method(id, payload, context))
except NotAuthorizedException as e:
return StatusCode.NOT_AUTHORIZED, getErrorArtifact(
id, str(e), StatusCode.NOT_AUTHORIZED
)
error = e
statuscode = StatusCode.NOT_AUTHORIZED
response = getErrorArtifact(id, str(e), StatusCode.NOT_AUTHORIZED)
except InvalidInputsException as e:
return StatusCode.INVALID_INPUTS, getErrorArtifact(
id, str(e), StatusCode.INVALID_INPUTS
)
error = e
statuscode = StatusCode.INVALID_INPUTS
response = getErrorArtifact(id, str(e), StatusCode.INVALID_INPUTS)
except NoProcessingException:
return StatusCode.NO_PROCESSING, None
statuscode = StatusCode.NO_PROCESSING
except MethodNotFoundException as e:
return StatusCode.METHOD_NOT_FOUND, getErrorArtifact(
id, str(e), StatusCode.METHOD_NOT_FOUND
)
error = e
statuscode = StatusCode.METHOD_NOT_FOUND
response = getErrorArtifact(id, str(e), StatusCode.METHOD_NOT_FOUND)
except Exception as e:
if self._config.get(f"conf.{self.name}.exiton5xx"):
print("Exiting due to 5xx error", e, flush=True)
exit(1)
return StatusCode.SERVER_ERROR, getErrorArtifact(
id, str(e), StatusCode.SERVER_ERROR
)
error = e
statuscode = StatusCode.SERVER_ERROR
response = getErrorArtifact(id, str(e), StatusCode.SERVER_ERROR)

if self._config.get(f"conf.{self.name}.exiton5xx") and statuscode.value >= 500:
print("Exiting due to 5xx error", error, flush=True)
exit(1)
if (
self._config.get(f"conf.{self.name}.exiton4xx")
and statuscode.value >= 400
and statuscode.value < 500
):
print("Exiting due to 5xx error", error, flush=True)
exit(1)

return statuscode, response

def inputProcessor(self, message: Any) -> StatusCode:
bus = self._busClass(
Expand Down
4 changes: 3 additions & 1 deletion servc/svc/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
"conf.bus.prefix": "",
"conf.worker.bindtoeventexchange": True,
"conf.worker.exiton5xx": True,
"conf.worker.exiton4xx": False,
}

BOOLEAN_CONFIGS = os.getenv(
"SERVC_BOOLEAN_CONFIGS", "conf.worker.exiton5xx,conf.worker.bindtoeventexchange"
"SERVC_BOOLEAN_CONFIGS",
"conf.worker.exiton4xx,conf.worker.exiton5xx,conf.worker.bindtoeventexchange",
).split(",")
DOT_MARKER = os.getenv("SERVC_DOT_MARKER", "_DOT_")
DASH_MARKER = os.getenv("SERVC_DASH_MARKER", "_DASH_")
Expand Down