Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 404 not found errors #116

Merged
merged 4 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
working_directory: ~/closex
docker:
- image: elixir:1.6
- image: elixir:1.10
environment:
COVERALLS_REPO_TOKEN: 3T8c9tUBXMAmGPmnBO1SUv7xGFr32gbLs
MIX_ENV: test
Expand Down
5 changes: 2 additions & 3 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
elixir 1.9.0
erlang 22.0.5

elixir 1.10.3
erlang 22.3.4
4 changes: 4 additions & 0 deletions lib/closex/http_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ defmodule Closex.HTTPClient do
{:error, response}
end

defp handle_response({:ok, response = %{status_code: 404}}) do
{:error, response}
end

defp handle_response({:ok, response = %{status_code: 429}}) do
{:error, response}
end
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ defmodule Closex.Mixfile do
def project do
[
app: :closex,
version: "1.4.7",
version: "2.0.0",
build_path: "_build",
config_path: "config/config.exs",
deps_path: "deps",
lockfile: "mix.lock",
elixirc_paths: elixirc_paths(Mix.env()),
elixir: "~> 1.6",
elixir: "~> 1.10",
description: description(),
package: package(),
deps: deps(),
Expand Down
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm", "32e95820a97cffea67830e91514a2ad53b888850442d6d395f53a1ac60c82e07"},
"exvcr": {:hex, :exvcr, "0.10.3", "1ae3b97560430acfa88ebc737c85b2b7a9dbacd8a2b26789a19718b51ae3522c", [:mix], [{:exactor, "~> 2.2", [hex: :exactor, repo: "hexpm", optional: false]}, {:exjsx, "~> 4.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:httpoison, "~> 1.0", [hex: :httpoison, repo: "hexpm", optional: true]}, {:httpotion, "~> 3.1", [hex: :httpotion, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:meck, "~> 0.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "484d856d5f4f6a1ba3a691b82fcd29c0a46cb56eb6ddfd2b1d7aca1061a46ec0"},
"file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm", "0d50da6b04c58e101a3793b1600f9a03b86e3a8057b192ac1766013d35706fa6"},
"hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"httpoison": {:hex, :httpoison, "1.6.2", "ace7c8d3a361cebccbed19c283c349b3d26991eff73a1eaaa8abae2e3c8089b6", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "e0100f8ef7d1124222c11ad362c857d3df7cb5f4204054f9f0f4a728666591fc"},
"httpoison": {:hex, :httpoison, "1.6.2", "ace7c8d3a361cebccbed19c283c349b3d26991eff73a1eaaa8abae2e3c8089b6", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "aa2c74bd271af34239a3948779612f87df2422c2fdcfdbcec28d9c105f0773fe"},
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fdf843bca858203ae1de16da2ee206f53416bbda5dc8c9e78f43243de4bc3afe"},
"jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm", "fc3499fed7a726995aa659143a248534adc754ebd16ccd437cd93b649a95091f"},
Expand All @@ -20,6 +20,6 @@
"mix_test_watch": {:hex, :mix_test_watch, "0.9.0", "c72132a6071261893518fa08e121e911c9358713f62794a90c95db59042af375", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "817dec4a7f6edf260258002f99ac8ffaf7a8f395b27bf2d13ec24018beecec8a"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm", "5c040b8469c1ff1b10093d3186e2e10dbe483cd73d79ec017993fb3985b8a9b3"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm", "13104d7897e38ed7f044c4de953a6c28597d1c952075eb2e328bc6d6f2bfc496"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"},
}
42 changes: 42 additions & 0 deletions test/fixtures/vcr_cassettes/merge_leads_not_found.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"request": {
"body": "{\"destination\":\"dont_find_me\",\"source\":\"lead_8xlzqZBSz6iKJJLoZ82Fh2vqcUzretDDBClxTmWgLJ1\"}",
"headers": {
"Content-Type": "application/json",
"Accept": "application/json"
},
"method": "post",
"options": {
"basic_auth": [
"FAKE_CLOSEIO_TOKEN:",
""
]
},
"request_body": "",
"url": "https://api.close.com/api/v1/lead/merge/"
},
"response": {
"binary": false,
"body": "{\"errors\":[\"Source lead does not exist.\"]}\n",
"headers": {
"date": "Thu, 06 Aug 2020 15:17:36 GMT",
"content-type": "application/json",
"content-length": "43",
"x-frame-options": "SAMEORIGIN",
"x-rate-limit-limit": "320",
"x-rate-limit-remaining": "319",
"x-rate-limit-reset": "7.699090",
"x-xss-protection": "1; mode=block",
"x-content-type-options": "nosniff",
"strict-transport-security": "max-age=31556926; includeSubDomains",
"referrer-policy": "no-referrer-when-downgrade",
"set-cookie": "session=; Expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/",
"x-envoy-upstream-service-time": "51",
"server": "envoy"
},
"status_code": 404,
"type": "ok"
}
}
]
38 changes: 38 additions & 0 deletions test/http_client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,44 @@ defmodule Closex.HTTPClientTest do
assert response == %{"status" => "ok"}
end
end

test "returns an error if it can't find one of the leads" do
use_cassette "merge_leads_not_found" do
{:error, response} = merge_leads(@source_lead_id, "dont_find_me")

assert response == %HTTPoison.Response{
body: %{"errors" => ["Source lead does not exist."]},
headers: [
{"content-length", "43"},
{"content-type", "application/json"},
{"date", "Thu, 06 Aug 2020 15:17:36 GMT"},
{"referrer-policy", "no-referrer-when-downgrade"},
{"server", "envoy"},
{"set-cookie",
"session=; Expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"},
{"strict-transport-security", "max-age=31556926; includeSubDomains"},
{"x-content-type-options", "nosniff"},
{"x-envoy-upstream-service-time", "51"},
{"x-frame-options", "SAMEORIGIN"},
{"x-rate-limit-limit", "320"},
{"x-rate-limit-remaining", "319"},
{"x-rate-limit-reset", "7.699090"},
{"x-xss-protection", "1; mode=block"}
],
request: %HTTPoison.Request{
body:
"{\"destination\":\"dont_find_me\",\"source\":\"lead_8xlzqZBSz6iKJJLoZ82Fh2vqcUzretDDBClxTmWgLJ1\"}",
headers: [{"Content-Type", "application/json"}, {"Accept", "application/json"}],
method: :post,
options: [hackney: [basic_auth: {"FAKE_CLOSEIO_TOKEN", ""}]],
params: %{},
url: "https://api.close.com/api/v1/lead/merge/"
},
request_url: "https://api.close.com/api/v1/lead/merge/",
status_code: 404
}
end
end
end

describe "log_call/1" do
Expand Down