Skip to content

Throw different exception for failed test op #49

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
merged 1 commit into from
Aug 29, 2022

Conversation

jakobw
Copy link
Contributor

@jakobw jakobw commented Aug 29, 2022

Hi! 👋

This PR adds a new exception type, which allows users of this library to distinguish between apply() errors due to the patch not being applicable and errors due to failed test operations.

Our (@wmde's) use case is a REST API with a PATCH endpoint which should have a different response for these two types of errors. We would like to do the following (simplified):

try {
	$patch->apply( $original );
} catch ( PatchTestOperationFailedException $e ) {
	// response saying the provided test operation failed
} catch ( Exception $e ) {
	// response saying the patch cannot be applied to the resource
}

As far as I can tell the only way to distinguish the two at the moment is by the exception message, which is a bit awkward to handle in code.

Having this additional exception type allows users to distinguish
between apply() errors due to the patch not being applicable and failed
test operations.
@jakobw jakobw force-pushed the test-op-exception branch from 02aabab to 9593b9e Compare August 29, 2022 14:58
@codecov
Copy link

codecov bot commented Aug 29, 2022

Codecov Report

Merging #49 (6a9078c) into master (6d7c9d5) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 6a9078c differs from pull request most recent head 9593b9e. Consider uploading reports for the commit 9593b9e to get more accurate results

@@           Coverage Diff           @@
##           master      #49   +/-   ##
=======================================
  Coverage   96.63%   96.63%           
=======================================
  Files          10       10           
  Lines         535      535           
=======================================
  Hits          517      517           
  Misses         18       18           
Impacted Files Coverage Δ
src/JsonPatch.php 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@vearutop vearutop merged commit 949e504 into swaggest:master Aug 29, 2022
@vearutop
Copy link
Member

Thank you, v3.9.0 tagged.

@jakobw
Copy link
Contributor Author

jakobw commented Aug 29, 2022

That was quick, thanks!

@jakobw jakobw deleted the test-op-exception branch August 30, 2022 12:12
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