softwaremill / softwaremill/tapir

Add possibility to access raw body when executing client call

Open
#2,114 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
1.5k
Forks
468
Avg merge
5h 37m
Merged PRs (30d)
34

Description

I'd like to access raw response body when my client call fails, so e.g. I can log it.

Right now if I have an endpoint: Endpoint[Unit,Unit,Nothing,Unit,Any] and do SttpClientInterpreter(SttpClientOptions.default).toRequest(endpoint, uri)(wsToPipe)(params).send(backend) I receive Response[DecodeResult[Either[E, O]]]. If this is unmapped error like 500, then we get Error(,java.lang.IllegalArgumentException: Cannot decode from: , request: GET http://localhost) which doesn't bring much value.

Usually I'd like to have the raw body in hand in such cases and log it.

I can see that in sttp there was similar issue https://github.com/softwaremill/sttp/issues/190 which was implemented with asBoth, however in tapir we don't have control over it (at least I can't see such option).

At the same time I wouldn't like to change my original endpoint to have raw String in response.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with SttpClientInterpreter.toRequest and the send flow described in the issue, then compare the referenced sttp asBoth approach. Define how an unmapped 500 response should expose its raw body without changing the endpoint's response type. Done means callers can access and log that body when decoding fails.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.