title: Unmarshalling error onFailure from http POST with spray.client
body: <p>I am very new to spray.io and scala for that matter, so I apologize in advance if I didn't get the terminology right here in regards to unmarshalling.</p>
  
  <p>I'm trying to get my hands on a HTTP POST response using a pipeline, it's expected to fail because I need an authorization header, but let's ignore that for now. </p>
  
  <p>If I use the chrome extension Postman to POST to the url, I get this response, plain and simple json:</p>
  
  <pre><code>{"status":"error","message":"You must identify yourself to access this resource.","url":"https://scrive.com/login"}
  </code></pre>
  
  <p>So I started with creating my own case class for this response, and implemented my own JsonProtocol, to unmarshal the response.</p>
  
  <pre><code>case class CreateFromTemplateResult(status: String, message: String, url: String)
  
  object ScriveJsonProtocol extends DefaultJsonProtocol {
    implicit val createFromTemplateResponseFormat = jsonFormat3(CreateFromTemplateResult)
  }
  </code></pre>
  
  <p>So now I'm all set, to run my pipeline, and recieve the response.</p>
  
  <pre><code>val pipeline = sendReceive ~&gt; unmarshal[CreateFromTemplateResult]
  
  val response = pipeline {
     Post("https://api-testbed.scrive.com/api/v1/createfromtemplate/1")
  }
  
  response onComplete {
     case Success(CreateFromTemplateResult(status, message, url)) =&gt;
        requestContext.complete("success")
  
     case Failure(error) =&gt;
        requestContext.complete(error.getMessage)
      }
  </code></pre>
  
  <p>The request completes and the onFailure case runs, but the error.getMessage is no longer json, as in the previous Postman example.</p>
  
  <pre><code>Status: 403 Forbidden
  Body: {"status":"error","message":"You must identify yourself to access this resource.","url":"https://scrive.com/login"}
  </code></pre>
  
  <p>So my question becomes, how to I unmarshal the error returned and it's Body into my CreateFromTemplateResult case? Or simply into json would do as well. I don't know if my onSuccess case will work either, I want the same behaviour for them both. I want them to be in my defined CreateFromTemplateResult format.</p>
  
  <pre><code> case class CreateFromTemplateResult(status: String, message: String, url: String)
  </code></pre>
  
  <p>Thank you very much for your time, and again, I apologize for my bad terminology.</p>