Skip to content

Commit

Permalink
Handle error; add CallError.original_error
Browse files Browse the repository at this point in the history
  • Loading branch information
amh4r committed Nov 3, 2023
1 parent 996bf1c commit 6c51879
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion inngest/_internal/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,16 @@ def call_function_sync(
if isinstance(call_res, execution.FunctionCallResponse):
# Only call this hook if we get a return at the function
# level.
middleware.after_execution_sync()
match middleware.after_execution_sync():
case result.Ok(_):
pass
case result.Err(err):
middleware.before_response_sync()
return CommResponse.from_error(
self._client.logger,
self._framework,
err,
)

comm_res = CommResponse.from_call_result(
self._client.logger,
Expand Down
4 changes: 4 additions & 0 deletions inngest/_internal/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import enum
import typing

import pydantic

from . import errors, event_lib, transforms, types


Expand Down Expand Up @@ -39,6 +41,7 @@ class CallError(types.BaseModel):
is_retriable: bool
message: str
name: str
original_error: object = pydantic.Field(exclude=True)
stack: str

@classmethod
Expand All @@ -48,6 +51,7 @@ def from_error(cls, err: Exception) -> CallError:
is_retriable=isinstance(err, errors.NonRetriableError) is False,
message=str(err),
name=type(err).__name__,
original_error=err,
stack=transforms.get_traceback(err),
)

Expand Down
2 changes: 1 addition & 1 deletion inngest/_internal/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def create_headers(
) -> dict[str, str]:
headers = {
const.HeaderKey.CONTENT_TYPE.value: "application/json",
const.HeaderKey.USER_AGENT.value: f"inngest-{const.LANGUAGE}:v{const.VERSION}",
const.HeaderKey.SDK.value: f"inngest-{const.LANGUAGE}:v{const.VERSION}",
const.HeaderKey.USER_AGENT.value: f"inngest-{const.LANGUAGE}:v{const.VERSION}",
}

if framework is not None:
Expand Down

0 comments on commit 6c51879

Please sign in to comment.