@@ -93,7 +93,16 @@ trait SttpApi extends SttpExtensions with UriInterpolator {
9393 }
9494 .showAs(" as string" )
9595
96- /** Reads the response as either a string (for non-2xx responses), or othweise as an array of bytes (without any
96+ /** Reads the response as a `String`, if the status code is 2xx. Otherwise, throws an [[HttpError ]] / returns a failed
97+ * effect. Use the `utf-8` charset by default, unless specified otherwise in the response headers.
98+ *
99+ * @see
100+ * the [[ResponseAs.orFail ]] method can be used to convert any response description which returns an `Either` into
101+ * an exception-throwing variant.
102+ */
103+ def asStringOrFail : ResponseAs [String ] = asString.orFail
104+
105+ /** Reads the response as either a string (for non-2xx responses), or otherwise as an array of bytes (without any
97106 * processing). The entire response is loaded into memory.
98107 */
99108 def asByteArray : ResponseAs [Either [String , Array [Byte ]]] = asEither(asStringAlways, asByteArrayAlways)
@@ -103,6 +112,15 @@ trait SttpApi extends SttpExtensions with UriInterpolator {
103112 */
104113 def asByteArrayAlways : ResponseAs [Array [Byte ]] = ResponseAs (ResponseAsByteArray )
105114
115+ /** Reads the response as an array of bytes, without any processing, if the status code is 2xx. Otherwise, throws an
116+ * [[HttpError ]] / returns a failed effect.
117+ *
118+ * @see
119+ * the [[ResponseAs.orFail ]] method can be used to convert any response description which returns an `Either` into
120+ * an exception-throwing variant.
121+ */
122+ def asByteArrayOrFail : ResponseAs [Array [Byte ]] = asByteArray.orFail
123+
106124 /** Deserializes the response as either a string (for non-2xx responses), or otherwise as form parameters. Uses the
107125 * `utf-8` charset by default, unless specified otherwise in the response headers.
108126 */
@@ -127,6 +145,15 @@ trait SttpApi extends SttpExtensions with UriInterpolator {
127145 asStringAlways(charset2).map(GenericResponseAs .parseParams(_, charset2)).showAs(" as params" )
128146 }
129147
148+ /** Deserializes the response as form parameters, if the status code is 2xx. Otherwise, throws an [[HttpError ]] /
149+ * returns a failed effect. Uses the `utf-8` charset by default, unless specified otherwise in the response headers.
150+ *
151+ * @see
152+ * the [[ResponseAs.orFail ]] method can be used to convert any response description which returns an `Either` into
153+ * an exception-throwing variant.
154+ */
155+ def asParamsOrFail : ResponseAs [String ] = asString.orFail
156+
130157 private [client4] def asSttpFile (file : SttpFile ): ResponseAs [SttpFile ] = ResponseAs (ResponseAsFile (file))
131158
132159 /** Uses the [[ResponseAs ]] description that matches the condition (using the response's metadata).
@@ -243,7 +270,8 @@ trait SttpApi extends SttpExtensions with UriInterpolator {
243270 // stream response specifications
244271
245272 /** Handles the response body by either reading a string (for non-2xx responses), or otherwise providing a stream with
246- * the response's data to `f`. The stream is always closed after `f` completes.
273+ * the response's data to `f`. The effect type used by `f` must be compatible with the effect type of the backend.
274+ * The stream is always closed after `f` completes.
247275 *
248276 * A non-blocking, asynchronous streaming implementation must be provided as the [[Streams ]] parameter.
249277 */
@@ -252,8 +280,23 @@ trait SttpApi extends SttpExtensions with UriInterpolator {
252280 ): StreamResponseAs [Either [String , T ], S with Effect [F ]] =
253281 asEither(asStringAlways, asStreamAlways(s)(f))
254282
283+ /** Handles the response body by providing a stream with the response's data to `f`, if the status code is 2xx.
284+ * Otherwise, returns a failed effect (with [[HttpError ]]). The effect type used by `f` must be compatible with the
285+ * effect type of the backend. The stream is always closed after `f` completes.
286+ *
287+ * A non-blocking, asynchronous streaming implementation must be provided as the [[Streams ]] parameter.
288+ *
289+ * @see
290+ * the [[ResponseAs.orFail ]] method can be used to convert any response description which returns an `Either` into
291+ * an exception-throwing variant.
292+ */
293+ def asStreamOrFail [F [_], T , S ](s : Streams [S ])(
294+ f : s.BinaryStream => F [T ]
295+ ): StreamResponseAs [T , S with Effect [F ]] = asStream(s)(f).orFail
296+
255297 /** Handles the response body by either reading a string (for non-2xx responses), or otherwise providing a stream with
256- * the response's data, along with the response metadata, to `f`. The stream is always closed after `f` completes.
298+ * the response's data, along with the response metadata, to `f`. The effect type used by `f` must be compatible with
299+ * the effect type of the backend. The stream is always closed after `f` completes.
257300 *
258301 * A non-blocking, asynchronous streaming implementation must be provided as the [[Streams ]] parameter.
259302 */
@@ -263,15 +306,17 @@ trait SttpApi extends SttpExtensions with UriInterpolator {
263306 asEither(asStringAlways, asStreamAlwaysWithMetadata(s)(f))
264307
265308 /** Handles the response body by providing a stream with the response's data to `f`, regardless of the status code.
266- * The stream is always closed after `f` completes.
309+ * The effect type used by `f` must be compatible with the effect type of the backend. The stream is always closed
310+ * after `f` completes.
267311 *
268312 * A non-blocking, asynchronous streaming implementation must be provided as the [[Streams ]] parameter.
269313 */
270314 def asStreamAlways [F [_], T , S ](s : Streams [S ])(f : s.BinaryStream => F [T ]): StreamResponseAs [T , S with Effect [F ]] =
271315 asStreamAlwaysWithMetadata(s)((s, _) => f(s))
272316
273317 /** Handles the response body by providing a stream with the response's data, along with the response metadata, to
274- * `f`, regardless of the status code. The stream is always closed after `f` completes.
318+ * `f`, regardless of the status code. The effect type used by `f` must be compatible with the effect type of the
319+ * backend. The stream is always closed after `f` completes.
275320 *
276321 * A non-blocking, asynchronous streaming implementation must be provided as the [[Streams ]] parameter.
277322 */
0 commit comments