Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6565583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:06:42+00:00 2026-05-25T14:06:42+00:00

Haskell newbie here. I’m attempting to use the http-enumerator to query a service via

  • 0

Haskell newbie here. I’m attempting to use the http-enumerator to query a service via XML over HTTP. I’m able to connect and send an xml-formatted request, and to receive the xml-formatted response.

When the query is successful, the server sends back a response starting with

What I’m struggling with is the correct way to handle the exceptions indicated in the FAULT document. I’m trying to use Either, but without success.

What I have below compiles in ghci:

import Network.HTTP.Enumerator 
import Network.HTTP.Types

import qualified Data.ByteString.Lazy as L 
import Data.ByteString.UTF8

import Text.XML.Light

hostname = "https://server..."

doPost username password token = do

    let q = QName "SYSTEM" Nothing Nothing

    let attribs = [Attr {attrKey = QName "user" Nothing Nothing, attrVal = username},
                   Attr {attrKey = QName "password" Nothing Nothing, attrVal = password},
                   Attr {attrKey = QName "token" Nothing Nothing, attrVal = token}]

    let doc = Element {elName=q, elAttribs=attribs, elContent= [], elLine=Nothing}

    req0 <- parseUrl hostname 

    let req = req0 { method = methodPost 
                  , requestHeaders = [("Content-Type", "text/xml")]   
                  , requestBody = RequestBodyBS $ fromString $ showTopElement doc
                  } 

    res <- withManager $ httpLbs req 

    let status = Network.HTTP.Enumerator.statusCode res
    let content = responseBody res

    -- this is where I would check for different fault codes using a case statement
    if content == "<FAULT/>"
        then Left "error"
        else Right content

However, when I attempt to run it in ghci I get the following:

*Main> doPost "user" "password" ""

<interactive>:1:1:
    No instances for (Control.Failure.Failure
                        HttpException (Either a0),
                      Control.Monad.IO.Control.MonadControlIO (Either a0))
      arising from a use of `doPost'
    Possible fix:
      add instance declarations for
      (Control.Failure.Failure HttpException (Either a0),
       Control.Monad.IO.Control.MonadControlIO (Either a0))
    In the expression: doPost "user" "password" ""
    In an equation for `it': it = doPost "user" "password" ""

What is the best way to handle exceptions in a case like this?

Thanks in advance.
Neil

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:06:43+00:00Added an answer on May 25, 2026 at 2:06 pm

    You need to put a “return $” before the last if. parseUrl needs to run in a monad which is an instance of Failure HttpException, such as IO or Maybe. withManager needs a monad which is an instance of MonadControlIO, such as IO.

    Currently, your if at the end is forcing the entire do-block to run in the Either String monad, which is why you’re getting the “no instance” exceptions. If you add a return, your final result will be something like IO (Either String XML).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Haskell newbie here. I wrote an evaluator for a minimal assembly-like language. Now, I
Complete Haskell newbie here, my apologies.... I am trying to create a sequence of
I am still a newbie to Haskell and I think I am over my
I am a Haskell newbie. I have noticed that Haskell does not support record
I am an absolute newbie in Haskell yet trying to understand how it works.
As a newbie to Haskell I am trying to iterate a function (e.g., the
I'm a haskell newbie and I couldn't find an answer to this question. Can
To Rephrase I am newbie to haskell. I am trying to parse a pcap
Haskell beginner here. I want to pass a type parameter with JSON, and have
I'm attempting to create a method in Haskell which I would think is very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.