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

Validate requests before sending #8

Merged
merged 1 commit into from
Aug 8, 2017

Conversation

cjab
Copy link
Contributor

@cjab cjab commented Aug 2, 2017

I ran into an error when attempting to make a get request without an explicit path (no trailing slash).

River.Client.get("https://localhost:4343")

I wrote a little bit of validation around creating requests that should set some reasonable defaults and return errors when the request is invalid.

be invalid.
"""
@spec new(URI.t, atom, any, headers) ::
{:ok, Request.t} | {:error, :invalid_uri} | {:error, :invalid_method}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added typespecs here. I realize the rest of the codebase doesn't have them but I think it would be a good idea to add them as we go. I think it helps a ton with documentation. That said I can remove them if you would rather not go that direction.

@@ -6,6 6,48 @@ defmodule River.RequestTest do
{ :ok, %{request: %Request{uri: URI.parse("https://google.com")}} }
end

describe "Request.new/4" do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also nested these tests in a describe block. The rest of the tests don't follow this pattern but it's something I'd like to propose. Again if you're against it I can unnest these :D.

Copy link
Owner

Choose a reason for hiding this comment

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

Not against this idea at all, in fact I much prefer organizing things this way.

@peburrows peburrows merged commit 0555871 into peburrows:master Aug 8, 2017
@peburrows
Copy link
Owner

This looks great, thanks @cjab!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants