After Handle can transform a response into a new response.
After Handle is like transform
, but instead of transforming the incoming request, it is used to transform a response returned from main handler.
Allowing you to remap the returned value into a new value or force the value to early return.
To use afterHandle
, you can either use in life-cycle event and inline hook.
The above code will return 3
as a result.
Sometimes you may want to prevent the on-going chain of afterHandle, just like beforeHandle. If you return the value in a afterHandle function, it will be an early return and skip the rest of afterHandle
The above code will return 2
as a result, because the onAfterHandle is early returned