title: Why Elixir Guardian (DB) has Problems finding token?
body: <p>I have Problems to understand, how guardian works or handles errors, so in this example, I simply try to logout and get errors on the console..</p>
  
  <p>code:</p>
  
  <pre class="lang-ruby prettyprint-override"><code>def delete(conn, _params) do
      {:ok, claims} = Guardian.Plug.claims(conn)
  
      conn
      |&gt; Guardian.Plug.current_token
      |&gt; Guardian.revoke!(claims)
  
      conn
      |&gt; render("delete.json")
  end
  </code></pre>
  
  <p>Somehow the token is not found even there is the session deleted, the user logged out. 
  I have problems to debug the code.
  How can I find errors or debug the code better?</p>
  
  <p>error message:</p>
  
  <pre><code>[error] #PID&lt;0.2061.0&gt; running PhoenixExample.Endpoint terminated
  Server: 127.0.0.1:4000 (http)
  Request: DELETE /api/v1/sessions
  ** (exit) an exception was raised:
      ** (Ecto.StaleEntryError) attempted to delete a stale struct:
  
  %GuardianDb.Token{__meta__: #Ecto.Schema.Metadata&lt;:loaded, "guardian_tokens"&gt;, aud: "User:96900", claims: %{"aud" =&gt; "User:96900", "exp" =&gt; 1474754356, "iat" =&gt; 1472162356, "iss" =&gt; "PhoenixExample", "jti" =&gt; "8947def5-ec3e-46e1-866d-2a1e9e16fd1f", "pem" =&gt; %{}, "sub" =&gt; "User:96900", "typ" =&gt; "token"}, exp: 1474754356, inserted_at: #Ecto.DateTime&lt;2016-08-25 21:59:16&gt;, iss: "PhoenixExample", jti: "8947def5-ec3e-46e1-866d-2a1e9e16fd1f", jwt: "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJVc2VyOjk2OTAwIiwiZXhwIjoxNDc0NzU0MzU2LCJpYXQiOjE0NzIxNjIzNTYsImlzcyI6IkNhbGx5YWNvcmUiLCJqdGkiOiI4OTQ3ZGVmNS1lYzNlLTQ2ZTEtODY2ZC0yYTFlOWUxNmZkMWYiLCJwZW0iOnt9LCJzdWIiOiJVc2VyOjk2OTAwIiwidHlwIjoidG9rZW4ifQ.BTYn7wjPlosztNmy3DKeRExzwBOiUG_ZLBJqUzUinDIpEl0xvUnb3EzYM7VaBpIT__JtVfZ0t7XET9D0LK0eMg", sub: "User:96900", typ: "token", updated_at: #Ecto.DateTime&lt;2016-08-25 21:59:16&gt;}
  
          (ecto) lib/ecto/repo/schema.ex:397: Ecto.Repo.Schema.apply/4
          (ecto) lib/ecto/repo/schema.ex:341: anonymous fn/9 in Ecto.Repo.Schema.do_delete/4
          lib/guardian_db.ex:98: GuardianDb.on_revoke/2
          (guardian) lib/guardian.ex:131: Guardian.revoke!/3
          (phoenixexample) web/controllers/api/v1/session_controller.ex:30: PhoenixExample.SessionController.delete/2
          (phoenixexample) web/controllers/api/v1/session_controller.ex:1: PhoenixExample.SessionController.action/2
          (phoenixexample) web/controllers/api/v1/session_controller.ex:1: PhoenixExample.SessionController.phoenix_controller_pipeline/2
          (phoenixexample) lib/phoenixexample/endpoint.ex:1: PhoenixExample.Endpoint.instrument/4
          (phoenixexample) lib/phoenix/router.ex:261: PhoenixExample.Router.dispatch/2
          (phoenixexample) web/router.ex:1: PhoenixExample.Router.do_call/2
          (phoenixexample) lib/phoenixexample/endpoint.ex:1: PhoenixExample.Endpoint.phoenix_pipeline/1
          (phoenixexample) lib/plug/debugger.ex:122: PhoenixExample.Endpoint."call (overridable 3)"/2
          (phoenixexample) lib/phoenixexample/endpoint.ex:1: PhoenixExample.Endpoint.call/2
          (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
          (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
  </code></pre>
  
  <p>conn (inspected)</p>
  
  <pre><code>%Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...}, assigns: %{},
   before_send: [#Function&lt;1.66364769/1 in Plug.Logger.call/2&gt;,
    #Function&lt;0.78287744/1 in Phoenix.LiveReloader.before_send_inject_reloader/1&gt;],
   body_params: %{}, cookies: %Plug.Conn.Unfetched{aspect: :cookies},
   halted: false, host: "127.0.0.1", method: "DELETE", owner: #PID&lt;0.2060.0&gt;,
   params: %{}, path_info: ["api", "v1", "sessions"],
   peer: {{127, 0, 0, 1}, 63006}, port: 4000,
   private: %{PhoenixExample.Router =&gt; {[], %{}},
     :guardian_default_claims =&gt; {:ok,
      %{"aud" =&gt; "User:96900", "exp" =&gt; 1474754356, "iat" =&gt; 1472162356,
        "iss" =&gt; "PhoenixExample", "jti" =&gt; "8947def5-ec3e-46e1-866d-2a1e9e16fd1f",
        "pem" =&gt; %{}, "sub" =&gt; "User:96900", "typ" =&gt; "token"}},
     :guardian_default_jwt =&gt; "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJVc2VyOjk2OTAwIiwiZXhwIjoxNDc0NzU0MzU2LCJpYXQiOjE0NzIxNjIzNTYsImlzcyI6IkNhbGx5YWNvcmUiLCJqdGkiOiI4OTQ3ZGVmNS1lYzNlLTQ2ZTEtODY2ZC0yYTFlOWUxNmZkMWYiLCJwZW0iOnt9LCJzdWIiOiJVc2VyOjk2OTAwIiwidHlwIjoidG9rZW4ifQ.BTYn7wjPlosztNmy3DKeRExzwBOiUG_ZLBJqUzUinDIpEl0xvUnb3EzYM7VaBpIT__JtVfZ0t7XET9D0LK0eMg",
     :guardian_default_resource =&gt; %PhoenixExample.User{__meta__: #Ecto.Schema.Metadata&lt;:loaded, "users"&gt;,
      account: nil, address: nil, approved: false, city: nil, country: nil,
      description: nil, email: "radosch@me.com",
      encrypted_password: "$2b$12$E8AOMRI6pVHLIuumenHMSOfCR8TRK4.HYaCSGQvrobgTYkWBdcV7m",
      firstname: nil, guid: nil, id: 96900,
      inserted_at: #Ecto.DateTime&lt;2016-08-05 01:06:19&gt;, is_provider: false,
      lastname: nil, password: nil, postcode: nil, tags: nil,
      updated_at: #Ecto.DateTime&lt;2016-08-05 01:06:19&gt;, username: "radosch"},
     :phoenix_action =&gt; :delete,
     :phoenix_controller =&gt; PhoenixExample.SessionController,
     :phoenix_endpoint =&gt; PhoenixExample.Endpoint, :phoenix_format =&gt; "json",
     :phoenix_layout =&gt; {PhoenixExample.LayoutView, :app},
     :phoenix_pipelines =&gt; [:api],
     :phoenix_route =&gt; #Function&lt;61.48695856/1 in PhoenixExample.Router.match_route/4&gt;,
     :phoenix_router =&gt; PhoenixExample.Router,
     :phoenix_view =&gt; PhoenixExample.SessionView,
     :plug_session_fetch =&gt; #Function&lt;1.82590416/1 in Plug.Session.fetch_session/1&gt;},
   query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1},
   req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
   req_headers: [{"host", "127.0.0.1:4000"}, {"content-length", "0"},
    {"connection", "keep-alive"}, {"accept", "*/*"},
    {"user-agent", "CallYa/1 CFNetwork/808.0.1 Darwin/16.0.0"},
    {"accept-language", "de-ch"},
    {"authorization",
     "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJVc2VyOjk2OTAwIiwiZXhwIjoxNDc0NzU0MzU2LCJpYXQiOjE0NzIxNjIzNTYsImlzcyI6IkNhbGx5YWNvcmUiLCJqdGkiOiI4OTQ3ZGVmNS1lYzNlLTQ2ZTEtODY2ZC0yYTFlOWUxNmZkMWYiLCJwZW0iOnt9LCJzdWIiOiJVc2VyOjk2OTAwIiwidHlwIjoidG9rZW4ifQ.BTYn7wjPlosztNmy3DKeRExzwBOiUG_ZLBJqUzUinDIpEl0xvUnb3EzYM7VaBpIT__JtVfZ0t7XET9D0LK0eMg"},
    {"accept-encoding", "gzip, deflate"}], request_path: "/api/v1/sessions",
   resp_body: nil, resp_cookies: %{},
   resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"},
    {"x-request-id", "bn5l49vfieh6mra9sq4toa9afcocq5c9"}], scheme: :http,
   script_name: [],
   secret_key_base: "A2LVGKIq88H3nrx6cx4PC7uWf/AAe9zcjwfCRFTx1X5xQ5KNvlLTzfxbGQxQctdb",
   state: :unset, status: nil}
  %Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...}, assigns: %{},
   before_send: [#Function&lt;1.66364769/1 in Plug.Logger.call/2&gt;,
    #Function&lt;0.78287744/1 in Phoenix.LiveReloader.before_send_inject_reloader/1&gt;],
   body_params: %{}, cookies: %Plug.Conn.Unfetched{aspect: :cookies},
   halted: false, host: "127.0.0.1", method: "DELETE", owner: #PID&lt;0.2061.0&gt;,
   params: %{}, path_info: ["api", "v1", "sessions"],
   peer: {{127, 0, 0, 1}, 63007}, port: 4000,
   private: %{PhoenixExample.Router =&gt; {[], %{}},
     :guardian_default_claims =&gt; {:ok,
      %{"aud" =&gt; "User:96900", "exp" =&gt; 1474754356, "iat" =&gt; 1472162356,
        "iss" =&gt; "PhoenixExample", "jti" =&gt; "8947def5-ec3e-46e1-866d-2a1e9e16fd1f",
        "pem" =&gt; %{}, "sub" =&gt; "User:96900", "typ" =&gt; "token"}},
     :guardian_default_jwt =&gt; "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJVc2VyOjk2OTAwIiwiZXhwIjoxNDc0NzU0MzU2LCJpYXQiOjE0NzIxNjIzNTYsImlzcyI6IkNhbGx5YWNvcmUiLCJqdGkiOiI4OTQ3ZGVmNS1lYzNlLTQ2ZTEtODY2ZC0yYTFlOWUxNmZkMWYiLCJwZW0iOnt9LCJzdWIiOiJVc2VyOjk2OTAwIiwidHlwIjoidG9rZW4ifQ.BTYn7wjPlosztNmy3DKeRExzwBOiUG_ZLBJqUzUinDIpEl0xvUnb3EzYM7VaBpIT__JtVfZ0t7XET9D0LK0eMg",
     :guardian_default_resource =&gt; %PhoenixExample.User{__meta__: #Ecto.Schema.Metadata&lt;:loaded, "users"&gt;,
      account: nil, address: nil, approved: false, city: nil, country: nil,
      description: nil, email: "radosch@me.com",
      encrypted_password: "$2b$12$E8AOMRI6pVHLIuumenHMSOfCR8TRK4.HYaCSGQvrobgTYkWBdcV7m",
      firstname: nil, guid: nil, id: 96900,
      inserted_at: #Ecto.DateTime&lt;2016-08-05 01:06:19&gt;, is_provider: false,
      lastname: nil, password: nil, postcode: nil, tags: nil,
      updated_at: #Ecto.DateTime&lt;2016-08-05 01:06:19&gt;, username: "radosch"},
     :phoenix_action =&gt; :delete,
     :phoenix_controller =&gt; PhoenixExample.SessionController,
     :phoenix_endpoint =&gt; PhoenixExample.Endpoint, :phoenix_format =&gt; "json",
     :phoenix_layout =&gt; {PhoenixExample.LayoutView, :app},
     :phoenix_pipelines =&gt; [:api],
     :phoenix_route =&gt; #Function&lt;61.48695856/1 in PhoenixExample.Router.match_route/4&gt;,
     :phoenix_router =&gt; PhoenixExample.Router,
     :phoenix_view =&gt; PhoenixExample.SessionView,
     :plug_session_fetch =&gt; #Function&lt;1.82590416/1 in Plug.Session.fetch_session/1&gt;},
   query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1},
   req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
   req_headers: [{"host", "127.0.0.1:4000"}, {"content-length", "0"},
    {"connection", "keep-alive"}, {"accept", "*/*"},
    {"user-agent", "CallYa/1 CFNetwork/808.0.1 Darwin/16.0.0"},
    {"accept-language", "de-ch"},
    {"authorization",
     "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJVc2VyOjk2OTAwIiwiZXhwIjoxNDc0NzU0MzU2LCJpYXQiOjE0NzIxNjIzNTYsImlzcyI6IkNhbGx5YWNvcmUiLCJqdGkiOiI4OTQ3ZGVmNS1lYzNlLTQ2ZTEtODY2ZC0yYTFlOWUxNmZkMWYiLCJwZW0iOnt9LCJzdWIiOiJVc2VyOjk2OTAwIiwidHlwIjoidG9rZW4ifQ.BTYn7wjPlosztNmy3DKeRExzwBOiUG_ZLBJqUzUinDIpEl0xvUnb3EzYM7VaBpIT__JtVfZ0t7XET9D0LK0eMg"},
    {"accept-encoding", "gzip, deflate"}], request_path: "/api/v1/sessions",
   resp_body: nil, resp_cookies: %{},
   resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"},
    {"x-request-id", "u3c2qbajf1a0fofhlg7hl4aa57gttqrl"}], scheme: :http,
   script_name: [],
   secret_key_base: "A2LVGKIq88H3nrx6cx4PC7uWf/AAe9zcjwfCRFTx1X5xQ5KNvlLTzfxbGQxQctdb",
   state: :unset, status: nil}
  </code></pre>