Skip to content
Open
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
4 changes: 1 addition & 3 deletions lib/origin_simulator/payload.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ defmodule OriginSimulator.Payload do

def body(_server, status, path \\ Recipe.default_route(), route \\ Recipe.default_route()) do
case {status, path} do
{200, _} -> cache_lookup(route)
{404, _} -> {:ok, "Not found"}
{406, "/*"} -> {:ok, OriginSimulator.recipe_not_set()}
{406, _} -> {:ok, OriginSimulator.recipe_not_set(path)}
_ -> {:ok, "Error #{status}"}
_ -> cache_lookup(route)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry maybe I'm missing the reasoning for this. I'm not sure why it's trying to fetch from cache for 404s

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah it's probably the discussion in Slack. It'd be useful to add a line in the PR desc

end
end

Expand Down
16 changes: 8 additions & 8 deletions test/origin_simulator/payload_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ defmodule OriginSimulator.PayloadTest do
Payload.fetch(:payload, origin_recipe())
end

test "Always return an error body for 5xx" do
assert Payload.body(:payload, 500) == {:ok, "Error 500"}
test "Always returns payload body for 5xx" do
assert Payload.body(:payload, 500) == {:ok, "some content from origin"}
end

test "Always return 'Not Found' for 404s" do
assert Payload.body(:payload, 404) == {:ok, "Not found"}
test "Always returns payload body for 404s" do
assert Payload.body(:payload, 404) == {:ok, "some content from origin"}
end

test "Suggests to add a recipe for 406" do
Expand All @@ -33,12 +33,12 @@ defmodule OriginSimulator.PayloadTest do
Payload.fetch(:payload, body_recipe())
end

test "Always return an error body for 5xx" do
assert Payload.body(:payload, 500) == {:ok, "Error 500"}
test "Always returns payload body for 5xx" do
assert Payload.body(:payload, 500) == {:ok, ~s({"hello":"world"})}
end

test "Always return 'Not Found' for 404s" do
assert Payload.body(:payload, 404) == {:ok, "Not found"}
test "Always returns payload body for 404s" do
assert Payload.body(:payload, 404) == {:ok, ~s({"hello":"world"})}
end

test "Suggests to add a recipe for 406" do
Expand Down