Skip to content

Commit a04d047

Browse files
Addressing Ruben's feedback
1 parent 5f50be5 commit a04d047

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

docs/utilities/idempotency.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ sequenceDiagram
482482
deactivate Persistence Layer
483483
Note over Response hook,Persistence Layer: Record status is COMPLETE and not expired
484484
Response hook->>Lambda: Response hook invoked
485-
Lambda-->>Client: Same response sent to client
485+
Lambda-->>Client: Manipulated idempotent response sent to client
486486
end
487487
```
488-
<i>Idempotent successful request with response hook</i>
488+
<i>Successful idempotent request with a response hook</i>
489489
</center>
490490

491491
#### Expired idempotency records
@@ -946,7 +946,7 @@ You can create your own persistent store from scratch by inheriting the `BasePer
946946

947947
### Manipulating the Idempotent Response
948948

949-
You can set up a `response_hook` in the `IdempotentConfig` class to access the returned data when an operation is idempotent. The hook function will be called with the current deserialized response object and the Idempotency record.
949+
You can set up a `response_hook` in the `IdempotentConfig` class to manipulate the returned data when an operation is idempotent. The hook function will be called with the current deserialized response object and the Idempotency record.
950950

951951
=== "Using an Idempotent Response Hook"
952952

@@ -966,15 +966,13 @@ You can set up a `response_hook` in the `IdempotentConfig` class to access the r
966966

967967
#### Being a good citizen
968968

969-
Using Response hooks can add subtle improvements to manipulating returned data from idempotent operations, but also add significant complexity if you're not careful.
970-
971-
Keep the following in mind when authoring hooks for Idempotency utility:
969+
When using response hooks to manipulate returned data from idempotent operations, it's important to follow best practices to avoid introducing complexity or issues. Keep these guidelines in mind:
972970

973-
1. **Response hook works exclusively when operations are idempotent.** Carefully consider the logic within the `Response hook` and prevent any attempt to access the key from relying exclusively on idempotent operations.
971+
1. **Response hook works exclusively when operations are idempotent.** The hook will not be called when an operation is not idempotent, or when the idempotent logic fails.
974972

975-
2. **Catch your own exceptions.** Catch and handle known exceptions to your logic.
973+
2. **Catch and Handle Exceptions.** Your response hook code should catch and handle any exceptions that may arise from your logic. Unhandled exceptions will cause the Lambda function to fail unexpectedly.
976974

977-
3. **Watch out when you are decorating the Lambda Handler and using the Response hook.** If you don't catch and handle exceptions in your `Response hook`, your function might not run properly.
975+
3. **Keep Hook Logic Simple** Response hooks should consist of minimal and straightforward logic for manipulating response data. Avoid complex conditional branching and aim for hooks that are easy to reason about.
978976

979977
## Compatibility with other utilities
980978

examples/idempotency/src/working_with_response_hook.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ def lambda_handler(event: dict, context: LambdaContext):
5353
logger.info(f"Processing order id {event.get('order_id')}")
5454
return process_order(order=event.get("order"))
5555
except Exception as err:
56-
return {"status_code": 400, "error": f"Erro processing {str(err)}"}
56+
return {"status_code": 400, "error": f"Error processing {str(err)}"}

0 commit comments

Comments
 (0)