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

return 404 for route not found #35

Merged
merged 4 commits into from
Apr 11, 2018

Conversation

sahlone
Copy link

@sahlone sahlone commented Jan 3, 2018

If there is no route, that means the future is successful but the server returned 404
If we think of it as an exception with failed future then it will suppress the semantics of
client failure vs HTTP failures. Caller should check for HTTP status rather than future state

@coveralls
Copy link

coveralls commented Jan 3, 2018

Coverage Status

Coverage increased (+0.3%) to 90.345% when pulling 2d9bb9f on sahilahmadlone:ISSUE#25-Fix-UnknownHostException into 4114d46 on leanovate:master.

ws.url("/url2").get() onComplete {
case Success(x)=> x.status should be(404)
case Failure(x)=> fail("should not throw an exception for url not found")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use await to directly assert the result of the Future:

await(ws.url("/url2").get()).status should be (404)

Copy link
Author

Choose a reason for hiding this comment

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

SOrry, didn't pay attention, it's not Async test.

//If we think of it as exception with failed future then it will suppress the semantics of
//client failure vs HTTP failures. Caller should check for HTTP status rather than future state
logger.debug(s"no route defined for $method $url")
Future.successful(Results.NotFound)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍
Thx for the comment also!

@yanns
Copy link
Collaborator

yanns commented Jan 4, 2018

What is your opinion about what to do when no route can be found?
In #25, one suggested to return a Future.failed(new UnknownHostException()).
In this PR, you decided to return a 404.
Can you share you opinion about your decision?

@sahlone
Copy link
Author

sahlone commented Jan 4, 2018

Perhaps the best way I can think of is if the function can take an implicit parameter noRouteAction : =>T, if the user wants to dictate the behavior and we can give some of our own to mock various expected behaviours.
What do you say?

@yanns
Copy link
Collaborator

yanns commented Jan 5, 2018

@sahilahmadlone that's a good idea. And we can provide a good default (like returning a 404)

@sahlone
Copy link
Author

sahlone commented Jan 5, 2018

Will work on it and let you know.

@leanovate leanovate deleted a comment Apr 10, 2018
@leanovate leanovate deleted a comment Apr 10, 2018
@sahlone
Copy link
Author

sahlone commented Apr 10, 2018

@yanns Can you have a look at it?

Copy link
Collaborator

@yanns yanns left a comment

Choose a reason for hiding this comment

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

Thx for the update, it looks good in general.

@@ -59,5 +61,19 @@ object MockWS {
* @param routes simulation of the external web resource
* @param materializer user-defined materializer
*/
def apply(routes: Routes, materializer: ActorMaterializer) = new MockWS(routes, () ⇒ Unit)(materializer)
def apply(routes: Routes, materializer: ActorMaterializer)(implicit fn: RouteNotDefined) = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer an apply without any implicit parameters:

def apply(routes: Routes, materializer: ActorMaterializer, notFoundBehaviour: RouteNotDefined) =
  new MockWS(routes, () ⇒ Unit)(materializer, notFoundBehaviour)

Copy link
Author

Choose a reason for hiding this comment

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

If we do that , then in this case it will be picked from implicit scope

Copy link
Author

Choose a reason for hiding this comment

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

I think what we can do is have only one apply and we put the defaults in implicit scope and the user can override if he wants to , what do you think ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually, by thinking again about it, you can let this code as it is now.

@@ -31,7 +33,7 @@ import play.api.mvc.EssentialAction
*
* @param routes routes defining the mock calls
*/
class MockWS(routes: MockWS.Routes, shutdownHook: () ⇒ Unit)(implicit val materializer: ActorMaterializer) extends WSClient {
class MockWS(routes: MockWS.Routes, shutdownHook: () ⇒ Unit)(implicit val materializer: ActorMaterializer, action: RouteNotDefined) extends WSClient {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the name notFoundBehaviour you used before.
Could you use it here instead of action?

Copy link
Author

Choose a reason for hiding this comment

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

here Here 2d9bb9f

trait RouteNotDefined extends (() => Future[Result])
object RouteNotDefined {

implicit val defaultAction:RouteNotDefined = RouteNotDefined(NotFound)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: add a whitespace between defaultAction: and RouteNotDefined

Copy link
Author

Choose a reason for hiding this comment

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

We can try to add a scalafmt plugin , maybe a new PR after this

Copy link
Author

Choose a reason for hiding this comment

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

Here 2d9bb9f

@@ -49,7 +51,7 @@ object MockWS {
/**
* @param routes simulation of the external web resource
*/
def apply(routes: Routes) = {
def apply(routes: Routes)(implicit fn: RouteNotDefined) = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here, please use notFoundBehaviour.

Copy link
Author

Choose a reason for hiding this comment

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

Here 2d9bb9f

Copy link
Collaborator

@yanns yanns left a comment

Choose a reason for hiding this comment

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

Thx a lot!
💯

@yanns yanns merged commit 00c1be2 into leanovate:master Apr 11, 2018
@sahlone
Copy link
Author

sahlone commented Apr 11, 2018

If you have any other project you need help with, give me a shout.

@leanovate leanovate deleted a comment from sahlone Apr 12, 2018
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.

None yet

3 participants