Fixed potential bad method call and premature email sending in bulk asset checkout #16546
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a potential to run into a hard 500 and also fixes the possibility of preemptively sending checkout emails when the bulk checkout ultimately fails.
I originally started to work on this because I noticed we attempted to call
getErrors()
off ofModelNotFoundException
but that method does not exist so we would get a 500 there.Now, if an id included in the request that is not found the user is redirected back with an error message:

Along the way I noticed that there was a scenario where a user might get a checkout email even though the bulk checkout fails. For example if the request has
[valid-id, invalid-id]
the user would get a checkout email for the first asset, since the id was valid, but the transaction would ultimately revert upon hitting theModelNotFoundException
on theinvalid-id
. MovingAsset:findOrFail()
up solves this issue.