Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Handle 5xx responses Spreedly Core #21

Merged
merged 2 commits into from
Jan 11, 2019
Merged

Conversation

jknipp
Copy link
Member

@jknipp jknipp commented Jan 10, 2019

Update response processing to handle 5xx responses by returning an
{:error, reason} tuple.

ENCEG-2362

@jknipp jknipp self-assigned this Jan 10, 2019
@jknipp jknipp requested a review from ptere January 10, 2019 19:56
@jknipp
Copy link
Member Author

jknipp commented Jan 10, 2019

@ptere There isn't a great way to test this. I made a change to my local Core and then ran the same call before and after (using the branch as a dependency) the change.

Version 2.1.0 (No changes)

iex(81)> Spreedly.list_supported_gateways
** (FunctionClauseError) no function clause matching in Spreedly.Base.process_response/1

    The following arguments were given to Spreedly.Base.process_response/1:

        # 1
        {:ok,
         %HTTPoison.Response{
           body: "<!DOCTYPE html>\n<html>\n<head>\n  <title>We're sorry, but something went wrong (500)</title>\n  <style type=\"text/css\">\n    body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }\n    div.dialog {\n      width: 25em;\n      padding: 0 4em;\n      margin: 4em auto 0 auto;\n      border: 1px solid #ccc;\n      border-right-color: #999;\n      border-bottom-color: #999;\n    }\n    h1 { font-size: 100%; color: #f00; line-height: 1.5em; }\n  </style>\n</head>\n\n<body>\n  <!-- This file lives in public/500.html -->\n  <div class=\"dialog\">\n    <h1>We're sorry, but something went wrong.</h1>\n    <p>We've been notified about this issue and we'll take a look at it shortly.</p>\n  </div>\n</body>\n</html>\n",
           headers: [
             {"Cache-Control", "no-cache"},
             {"Content-Length", "728"},
             {"Content-Type", "application/json; charset=utf-8"},
             {"X-Content-Type-Options", "nosniff"},
             {"X-Frame-Options", "SAMEORIGIN"},
             {"X-Request-Id", "core_fb4634362fc576fa1060d594b88ce14f"},
             {"X-Xss-Protection", "1; mode=block"},
             {"Date", "Thu, 10 Jan 2019 20:12:32 GMT"}
           ],
           request_url: "http://core.spreedly.test/v1/gateways_options.json?",
           status_code: 500
         }}

    Attempted function clauses (showing 6 out of 6):

        defp process_response({:ok, %HTTPoison.Response{status_code: code, body: body}}) when code === 201 or (code === 202 or code === 200)
        defp process_response({:ok, %HTTPoison.Response{status_code: code, body: body}}) when code === 402 or (code === 404 or code === 401)
        defp process_response({:ok, %HTTPoison.Response{status_code: code, body: body}}) when code === 403 or code === 422
        defp process_response({:ok, %HTTPoison.Response{status_code: code}}) when code === 408
        defp process_response({:ok, %HTTPoison.Response{status_code: code}}) when code === 429
        defp process_response({:error, %HTTPoison.Error{reason: reason}})

    (spreedly) lib/spreedly/base.ex:47: Spreedly.Base.process_response/1

Version 2.1.1 (Post changes)

iex(2)> Spreedly.list_supported_gateways
{:error, "500 Internal Server Error"}

500 => "Internal Server Error",
501 => "Not Implemented",
502 => "Bad Gateway",
503 => "Service Unavailable - Spreedly is temporarily unable to process the request.",
503 => "Service Unavailable. See https://docs.spreedly.com/reference/api/v1/#429-too-many-requests",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update response processing to handle 5xx responses by returning an
{:error, reason} tuple.

ENCEG-2362

Successful Full Test Suite Run at 2019-01-10 13:47:41
@jknipp jknipp force-pushed the ENCEG-2362-handle-500-errors branch from 4e03185 to ac8176d Compare January 11, 2019 22:11
@jknipp jknipp merged commit ac8176d into master Jan 11, 2019
@jknipp jknipp deleted the ENCEG-2362-handle-500-errors branch January 11, 2019 22:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants