Page MenuHomePhabricator

๐Ÿšจ Use exceptions instead of response objects in previous use cases
Closed, ResolvedPublic

Related Objects

Event Timeline

Muhammad_Yasser_Jazirahly_WMDE renamed this task from Use exceptions instead of response objects in previous UseCases to Use exceptions instead of response objects in previous use cases.Feb 17 2023, 4:10 PM

After using exceptions instead of response objects in the latest use case DescriptionsUseCase (T327881), and agreeing on using exceptions in the future, the remaining thing would be to modify older use cases.

Modifying older use cases plan:

  • Use cases to be modified:
  • Modify use cases to use exceptions instead of response objects.
  • Modify validators by:
    • Move the validation logic into the validator, in a new method assertValidRequest.
    • Throw a UseCaseException inside the new method. (Would it always be this exception? Or is only for the invalid item ID?)
  • Modify related route handler.
  • Since there is now only one response for use cases (the SuccessResponse), we will rename it to just Response.
  • Modify related tests.
Muhammad_Yasser_Jazirahly_WMDE renamed this task from Use exceptions instead of response objects in previous use cases to ๐Ÿšจ Use exceptions instead of response objects in previous use cases.Feb 20 2023, 8:01 AM

Mini task breakdown to cleanup:

  • In ResponseFactory, change newErrorResponse( ErrorResponse $useCaseResponse ) parameters to newErrorResponse( string $code, string $message, ?array $context )
  • Remove the ErrorJsonPresenter and instead do the json_encode in the ResponseFactory::newErrorResponse method
  • In the relevant middlewares, adjust the newErrorResponse arguments to match the parameter change
  • Modify newErrorResponseFromException to get rid of the new ErrorResponse( ... ) and pass in the three arguments directly
  • Move all public const error codes from ErrorResponse to UseCaseException
  • Delete the ErrorResponse class
  • Delete the ItemRedirectResponse class
  • Discuss whether ItemRedirectException should be a subclass of UseCaseException or not

Change 896367 had a related patch set uploaded (by Silvan Heintze; author: Silvan Heintze):

[mediawiki/extensions/Wikibase@master] REST: Remove ErrorResponse from ResponseFactory

https://gerrit.wikimedia.org/r/896367

Change 896376 had a related patch set uploaded (by Silvan Heintze; author: Silvan Heintze):

[mediawiki/extensions/Wikibase@master] REST: Remove ErrorResponse

https://gerrit.wikimedia.org/r/896376

Change 896383 had a related patch set uploaded (by Ollie Shotton; author: Ollie Shotton):

[mediawiki/extensions/Wikibase@master] REST: Remove ErrorJsonPresenter.php

https://gerrit.wikimedia.org/r/896383

Change 896384 had a related patch set uploaded (by Ollie Shotton; author: Ollie Shotton):

[mediawiki/extensions/Wikibase@master] REST: Remove ItemRedirectResponse.php

https://gerrit.wikimedia.org/r/896384

Change 896367 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Remove ErrorResponse from ResponseFactory

https://gerrit.wikimedia.org/r/896367

Change 896376 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Remove ErrorResponse

https://gerrit.wikimedia.org/r/896376

Change 896383 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Remove ErrorJsonPresenter.php

https://gerrit.wikimedia.org/r/896383

Change 896384 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Remove ItemRedirectResponse.php

https://gerrit.wikimedia.org/r/896384