commercetools-ios-sdk icon indicating copy to clipboard operation
commercetools-ios-sdk copied to clipboard

Support HTML error responses

Open nikola-mladenovic opened this issue 7 years ago • 4 comments

An example HTML error response that should be supported:

15:11 $ curl -v -XPOST ***.com
* Rebuilt URL to: ***.com/
*   Trying 35.186.251.105...
* Connected to ***.com (***) port 80 (#0)
> POST / HTTP/1.1
> Host: ***.com
> User-Agent: curl/7.43.0
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 411 Length Required
< Content-Type: text/html; charset=UTF-8
< Content-Length: 1564
< Date: Wed, 22 Mar 2017 14:11:13 GMT
<
<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 411 (Length Required)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>411.</b> <ins>That’s an error.</ins>
  <p>POST requests require a <code>Content-length</code> header.  <ins>That’s all we know.</ins>
* Closing connection 0

nikola-mladenovic avatar Mar 22 '17 14:03 nikola-mladenovic

Currently, when the HTML response is received the following error will be passed to the client: AFError.ResponseSerializationFailureReason.jsonSerializationFailed

nikola-mladenovic avatar Mar 24 '17 11:03 nikola-mladenovic

In order to change this, we would need to stop using responseJSON (which gives us automatic JSON response serialization) Alamofire method calls from all of our endpoints. Instead, we'd manually process the HTTPURLResponse and use JSONSerialization or just return the plain HTML body if the LB returned an error.

@cneijenhuis - do you think we should proceed?

nikola-mladenovic avatar Mar 24 '17 11:03 nikola-mladenovic

This looks like a bigger refactoring, and we've currently got more valuable tasks we can spend this time on.

Also, I still hope that the Google Cloud LB will implement JSON responses for clients that request JSON. It seems like a quite basic feature for a Load Balancer for APIs...

Let's keep this issue open though, and we may re-prioritize this in the future.

cneijenhuis avatar Mar 24 '17 18:03 cneijenhuis

Agreed, thank you! 👍

nikola-mladenovic avatar Mar 24 '17 19:03 nikola-mladenovic