Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #4

Merged
merged 1 commit into from
Aug 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end

## Usage

First add the request tracker to your supervision tree:
First, add the request tracker to your supervision tree:

```elixir
defmodule MyApp.Application do
Expand Down Expand Up @@ -85,11 +85,11 @@ plug IdempotencyPlug,
def scope_idempotency_key(conn, key), do: {conn.assigns.current_user.id, key}
```

Otherwise you may have a security vulnerability (or conflict) where any user can access another users cached responses when requests are identical.
Otherwise, you may have a security vulnerability (or conflict) where any user can access another user's cached responses when requests are identical.

## Customize error response

By default, errors are raised and handled by the `Plug.Exception` protocol, but you can handle the errors setting the `:with` option:
By default, errors are raised and handled by the `Plug.Exception` protocol, but you can handle the errors by setting the `:with` option:

```elixir
plug IdempotencyPlug,
Expand All @@ -98,15 +98,15 @@ plug IdempotencyPlug,

def handle_error(conn, error) do
conn
|> put_status(Plug.Expetion.Handler.status(error))
|> put_status(Plug.Exception.Handler.status(error))
|> json(%{error: error.message})
|> halt()
end
```

## Phoenix tests

For your controller tests you may want to add this helper to set up the idempotency key:
For your controller tests, you may want to add this helper to set up the idempotency key:

```elixir
def setup_with_idempotency_key(%{conn: conn}) do
Expand Down
Loading