Fix "Undefined variable: responseAjax" notice when trying to save a shipment package #12091
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.
Description
When creating a shipping label and the post to /admin/order_shipment/save/order_id//?isAjax=true fails, the real error is obscured because of a NOTICE about responseAjax being undefined at line 168 of vendor/magento/module-shipping/Controller/Adminhtml/Order/Shipment/Save.php. There is no reason the responseAjax object needs to be defined inside the try/catch block. Moving this up before the try/catch will resolve the issue of it not being defined prior to an exception being thrown.
Manual testing scenarios
In my specific case, the following message was prevented from being displayed:
"We don't have enough information to create shipping labels. Please make sure your store information and settings are complete."
This message isn't relevant for this pull request but demonstrates what the expected result was