raboof commented on code in PR #799:
URL: https://github.com/apache/pekko-connectors/pull/799#discussion_r1757138712


##########
google-common/src/main/scala/org/apache/pekko/stream/connectors/google/ResumableUpload.scala:
##########
@@ -93,10 +94,16 @@ private[connectors] object ResumableUpload {
     import implicits._
 
     implicit val um: FromResponseUnmarshaller[Uri] =
-      Unmarshaller.withMaterializer { implicit ec => implicit mat => 
(response: HttpResponse) =>
-        response.discardEntityBytes().future.map { _ =>
-          response.header[Location].fold(throw 
InvalidResponseException(ErrorInfo("No Location header")))(_.uri)
-        }
+      Unmarshaller.withMaterializer { _ => implicit mat => (response: 
HttpResponse) =>
+        if (response.status.isSuccess())
+          response.discardEntityBytes().future.map { _ =>
+            response.header[Location].fold(throw 
InvalidResponseException(ErrorInfo("No Location header")))(_.uri)
+          }(ExecutionContexts.parasitic)
+        else
+          Unmarshal(response.entity).to[String].flatMap { errorString =>
+            Future.failed(InvalidResponseException(
+              ErrorInfo(s"Resumable upload failed with status 
${response.status}: $errorString")))

Review Comment:
   responding with the status code instead of a misleading `No Location header` 
is a great improvement.



##########
google-common/src/main/scala/org/apache/pekko/stream/connectors/google/ResumableUpload.scala:
##########
@@ -93,10 +94,16 @@ private[connectors] object ResumableUpload {
     import implicits._
 
     implicit val um: FromResponseUnmarshaller[Uri] =
-      Unmarshaller.withMaterializer { implicit ec => implicit mat => 
(response: HttpResponse) =>
-        response.discardEntityBytes().future.map { _ =>
-          response.header[Location].fold(throw 
InvalidResponseException(ErrorInfo("No Location header")))(_.uri)
-        }
+      Unmarshaller.withMaterializer { _ => implicit mat => (response: 
HttpResponse) =>
+        if (response.status.isSuccess())
+          response.discardEntityBytes().future.map { _ =>
+            response.header[Location].fold(throw 
InvalidResponseException(ErrorInfo("No Location header")))(_.uri)
+          }(ExecutionContexts.parasitic)
+        else
+          response.entity.dataBytes.runWith(Sink.fold(ByteString.empty)(_ ++ 
_)).flatMap { body =>
+            Future.failed(InvalidResponseException(
+              ErrorInfo(s"Bad response, status code: 
${response.status.intValue()} and body: $body")))

Review Comment:
   While this is client code, it's plausible that this client would be used in 
some web application, with the exception bubbling up to the server-side 
exception handling.
   
   It might be unlikely that the server would be user-controllable or pointing 
to an untrusted server, exposing the response body could still leak sensitive 
information. I think it'd be sensible to move that to the `details` in both 
cases.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to