Passing the response from @on to the @after method
See original GitHub issueHello,
I have the following scenario:
@on(Action.RequestStartTransaction)
async def on_request_start_transaction(
self,
*args,
**kwargs
) -> call_result.RequestStartTransactionPayload:
response: call_result.RequestStartTransactionPayload = (
await TransactionHandler.handle_on_request_start_transaction(**kwargs)
)
# at this point, the response can be accepted
# or it can be rejected
return response
@after(Action.RequestStartTransaction)
async def after_request_start_transaction(
self,
*args,
**kwargs
) -> call_result.TransactionEventPayload:
# at this point, I would like to run this method conditionally,
# only if the response sent back to the CSMS was accepted
# if it was rejected, I do not want to run this method
return await TransactionHandler.handle_after_request_start_transaction(**kwargs)
Looking at charge_point.py
, it looks like it is the payload from the initial call which is passed into the @after
function. What would you think of also passing through the response of the call so that it can be used for further processing?
I have a workaround by using a temp variable, but thought it could be a nice feature of the library so posting here.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
javascript - Express: Pass the response of a method to another ...
You can do this by promise chaining app.post('/.custom-token', function (req, res, nex) { var token = null; //part ONE admin.auth().
Read more >Grails 3.0.4: After method in Interceptors does not allow ...
When setting FALSE in 'after' method in interceptor, I was previously able to still send a REST response (even if I was not...
Read more >Promise.prototype.then() - JavaScript - MDN Web Docs
The then() method of a Promise object takes up to two arguments: callback functions for the fulfilled and rejected cases of the Promise....
Read more >HTTP Request Methods – Get vs Put vs Post Explained with ...
In this article, we'll be discussing the get, put, and post HTTP methods. You'll learn what each HTTP method is used for as...
Read more >API — Flask Documentation (2.2.x)
It is passed the name of the module or package of the application. ... Add the OPTIONS method and respond to OPTIONS requests...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The routing system of this library is not very sophisticated and could use some improvement.
In the current implementation, the
@on()
handler is executed and it’s return value is send as response to the other peer. Next, the@after()
handler is executed. The return value of the@after()
handler is ignored.I’m afraid that above process might not be clear to all users of this library. In fact, the code sample that @HugoJP1 seem to indicate that this is not clear for them, as the
@after()
contains areturn
statement. Although this return value doesn’t do anything. Don’t get me wrong, that is a fault of the API, not of the users.Assume for now, return value of the
@on()
handler is passed down to the@after()
handler. Modifying the response and trying return it won’t send the modified response to the other peer. Here a code sample that shows invalid use of the proposed API:In retrospect, the current api of
@on()
and@after()
is too limiting. And we could use a better one. Maybe this ticket can serve as a discussion.One quick proposal, that I didn’t thought through yet is to allow preprocessing of requests,and post-processing of response. E.g.
It might even be made backwards compatible.
@tropxy Did you manage to do it? If so, can you share an example with us? Thanks