Skip to content

Implement default response and exception #21

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

Merged

Conversation

soullivaneuh
Copy link
Contributor

@soullivaneuh soullivaneuh commented Nov 7, 2017

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets fixes #20 as an alternative
Documentation php-http/documentation#212
License MIT

What's in this PR?

It allows to set a default response or exception if we don't care about what to returns but can't return an empty one.

Why?

This implements an idea from @dbu (#3 (comment)).

But this is a partial resolution of #3 only.

Example Usage

See the documentation PR.

Checklist

  • Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix
  • Documentation pull request created (if not simply a bugfix)

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

looks useful to me!

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

noticed that the doc comments could be more specific

src/Client.php Outdated
@@ -82,6 +100,16 @@ public function addException(\Exception $exception)
}

/**
* Sets the default exception to throw if none added.
Copy link
Contributor

Choose a reason for hiding this comment

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

... to throw when the list of added exceptions and responses is exhausted.

and maybe add a second bit saying "If both a default exception and a default response are set, the exception will be thrown."

src/Client.php Outdated
@@ -92,6 +120,16 @@ public function addResponse(ResponseInterface $response)
}

/**
* Sets the default response to be returned if none added.
Copy link
Contributor

Choose a reason for hiding this comment

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

same as for setDefaultException

@soullivaneuh soullivaneuh force-pushed the default-response-exception branch from 5ff102f to 9490607 Compare November 8, 2017 12:17
@soullivaneuh
Copy link
Contributor Author

@dbu updated.

@sagikazarmark
Copy link
Member

Thanks a lot @soullivaneuh

@sagikazarmark sagikazarmark merged commit 5edc24d into php-http:master Nov 10, 2017
@soullivaneuh soullivaneuh deleted the default-response-exception branch November 10, 2017 10:36
@soullivaneuh
Copy link
Contributor Author

You are welcome! 👍

Any chance to have a new minor release for that? :-)

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.

Provide a mock message factory
3 participants