Skip to content

Uncaught xhr exception #58

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

Closed
codedmart opened this issue Jan 27, 2016 · 0 comments
Closed

Uncaught xhr exception #58

codedmart opened this issue Jan 27, 2016 · 0 comments

Comments

@codedmart
Copy link
Contributor

I had the following code:

import Prelude
import Control.Monad.Eff (Eff())
import Control.Monad.Eff.Console (CONSOLE(), log)

import Control.Monad.Eff.Exception
import Control.Monad.Aff
import qualified Network.HTTP.Affjax as A
import Network.HTTP.Affjax.Request
import Network.HTTP.Affjax.Response
import Network.HTTP.Method
import Network.HTTP.RequestHeader
import Browser.WebStorage
import Data.Maybe
import Data.Either
import Data.Either.Unsafe

main :: forall e. Eff _ Unit
main = do
  runAff throwException log fetchCurrentAuth

fetchCurrentAuth :: forall eff. Aff _ String
fetchCurrentAuth = do
  token <- liftEff' $ getItem localStorage "Authorization"
  let tok = fromMaybe "" $ fromRight token
  let request = A.defaultRequest
        { url = "url"
        , method = GET
        , headers =
          [ RequestHeader "Content-Type" "application/json"
          , RequestHeader "Accept" "application/json"
          , RequestHeader "Authorization" tok
          ]
        }
  result <- A.affjax request :: A.Affjax _ String
  return $ tok <> result.response

The problem ended up being that my token from localStorage had a \n on the end of it and when debugging the outputted js I was getting this error Failed to execute 'setRequestHeader' on 'XMLHttpRequest' […] is not a valid HTTP header field value that affjax is not catching.

codedmart added a commit to codedmart/purescript-affjax that referenced this issue Jan 27, 2016
codedmart added a commit to codedmart/purescript-affjax that referenced this issue Jan 27, 2016
codedmart added a commit to codedmart/purescript-affjax that referenced this issue Jan 27, 2016
codedmart added a commit to codedmart/purescript-affjax that referenced this issue Jan 27, 2016
@garyb garyb closed this as completed in 01d8b33 Jan 30, 2016
garyb added a commit that referenced this issue Jan 30, 2016
catch errors in setRequestHeader, Fixes #58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant