Skip to content

Commit

Permalink
Fix a typo re: on_response -> on_complete
Browse files Browse the repository at this point in the history
  • Loading branch information
olleolleolle committed Oct 23, 2020
1 parent 0977306 commit 4e9f4b0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/middleware/custom.md
Expand Up @@ -48,10 +48,12 @@ later, response. Some keys are:
There's an easier way to write middleware, and it's also the recommended one: make your middleware subclass `Faraday::Middleware`.
`Faraday::Middleware` already implements the `#call` method for you and looks for two methods in your subclass: `#on_request(env)` and `#on_complete(env)`.
`#on_request` is called when the request is being built and is given the `env` representing the request.

`#on_complete` is called after the response has been received (that's right, it already supports parallel mode!) and receives the `env` of the response.

### Do I need to override `#call`?

For the majority of middleware, it's not necessary to override the `#call` method, as you can simply use `#on_request` and `#on_response`.
For the majority of middleware, it's not necessary to override the `#call` method. You can instead use `#on_request` and `#on_complete`.

However, in some cases you may need to wrap the call in a block, or work around it somehow (think of a begin-rescue, for example).
When that happens, then you can simply override `#call`. When you do so, remember to call either `app.call(env)` or `super` to avoid breaking the middleware stack call!
When that happens, then you can override `#call`. When you do so, remember to call either `app.call(env)` or `super` to avoid breaking the middleware stack call!

0 comments on commit 4e9f4b0

Please sign in to comment.