Spoke too soon

Exception in thread "main"
akka.http.scaladsl.unmarshalling.Unmarshaller$EitherUnmarshallingException:
Failed to unmarshal Either[AddUserErrorDTO, AddUserResponseDTO] (attempted
AddUserResponseDTO first). Right failure: Object is missing required member
'id', Left failure: Substream Source cannot be materialized more than once

Do I need to place a toStrict somewhere in my for comprehension?



On Tue, Aug 22, 2017 at 12:28 PM, Richard Rodseth <rrods...@gmail.com>
wrote:

> Having some success with Either unmarshaller. I don't think it's
> documented, but here's a test:
>
> https://github.com/akka/akka-http/blob/master/akka-http-
> tests/src/test/scala/akka/http/scaladsl/unmarshalling/
> UnmarshallingSpec.scala
>
> On Tue, Aug 22, 2017 at 11:16 AM, Richard Rodseth <rrods...@gmail.com>
> wrote:
>
>> I'm trying to use Akka HTTP client (singleRequest) with an API that
>> returns different JSON for the success and error cases. How is that best
>> handled? Also, I'm not sure if the explicit marshalling and unmarshalling
>> below is the right way to do things.
>>
>> Any help much appreciated.
>>
>> def addUser(baseURL: String, userAttributes: AddUserRequestDTO,
>> cookieHeader: Cookie)(implicit http: HttpExt, materializer: Materializer,
>> ec: ExecutionContext) = {
>>     val headers = List(cookieHeader)
>>     val addUserURL = ...
>>
>>     val responseFuture = for {
>>       requestEntity <- Marshal(userAttributes).to
>>     val request = HttpRequest(method = HttpMethods.POST, uri =
>> addUserURL, headers = headers, entity = requestEntity)
>>       response <- http.singleRequest(request)
>>       x <- Unmarshal(response.entity).to[AddUserResponseDTO]
>>       //body <- response.entity.dataBytes.runFold(ByteString(""))(_ ++ _)
>>       //val x = body.utf8String
>>     } yield (response, x)
>>     responseFuture
>>
>>   }
>>
>
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to