Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
To reproduce:
1. Create an AJAX request to your drupal application
2. When handling the AJAX request, cause a TypeError
Expected behaviour:
The AJAX request returns with a 500 (bad request) http status code
Actual behaviour:
The AJAX request returns with a 200 (ok) http status code
Context:
Ubuntu 16.04.2 LTS
Php 7.1.5
Apache 2.4.18
Comment | File | Size | Author |
---|---|---|---|
#28 | 2892370-28.patch | 3.8 KB | gstivanin |
| |||
#19 | 2892370-19.patch | 3.85 KB | alexpott |
#19 | 2892370-19.test-only.patch | 2.99 KB | alexpott |
#11 | ajax_error_handling-3.patch | 835 bytes | PtrTon |
#8 | ajax_error_handling-2.patch | 2.44 KB | PtrTon |
Comments
Comment #2
cilefen CreditAttribution: cilefen commentedComment #3
cilefen CreditAttribution: cilefen commentedComment #4
jsst CreditAttribution: jsst at Ibuildings commentedThis patch does not work as advertised: it only sends a 500 status code when Drupal is configured to display errors. I'd expect a 500 response regardless of the error level.
The patch in #2688999 seems to take care of this point, so in combination these two should work. Note the patch in #2688999 by itself is not enough to deal with the issue describe here. For example:
Above snippet will result in a 200 OK response message.
Comment #5
PtrTon CreditAttribution: PtrTon commentedComment #6
cilefen CreditAttribution: cilefen commentedComment #8
PtrTon CreditAttribution: PtrTon commentedComment #9
PtrTon CreditAttribution: PtrTon commentedComment #10
jsst CreditAttribution: jsst at Ibuildings commentedThe new patch combines the fix for AJAX error handling with the patch from #2688999. Since that one has the tag "needs work", it's only fair to say this one needs work too :)
I don't think we should combine those patches because they are separate issues. Why not try to fix the error handling specifically for AJAX requests, something like:
That way, this patch could be merged into core without depending on #2688999.
Comment #11
PtrTon CreditAttribution: PtrTon commentedAgreed with jsst, let's keep the scope of this issue to AJAX requests only. Updated patch accordingly.
Comment #12
PtrTon CreditAttribution: PtrTon commentedComment #13
jsst CreditAttribution: jsst at Ibuildings commentedComment #14
cilefen CreditAttribution: cilefen commentedThank you, everyone, for working on this. I think this work should be postponed on #2688999: Default all responses to 500 before any code is run so PHP will throw 500's on FATAL errors because setting http_response_code(500) will be redundant after #2688999 is finished.
I am surprised the #11 patch applies because it is targeting a top-level web/ directory that does not exist in Drupal core.
@jsst For your reference, please read about the core gates for reviewing purposes. In particular, this one would need a test.
Comment #18
alexpottThe related issue #2688999: Default all responses to 500 before any code is run so PHP will throw 500's on FATAL errors has got stuck. I think we should continue here as regardless of what happens in #2688999: Default all responses to 500 before any code is run so PHP will throw 500's on FATAL errors fixing this particular bug is a good idea.
Comment #19
alexpottHere's a fix plus a test so we don't break this in the future.
Comment #20
vijaycs85+1
good to send the response back, if the error display isn't on.
Comment #23
alexpottPretty sure the Drupal\Tests\field_layout\FunctionalJavascript\FieldLayoutTest fail is regular random JS test fail. Passes locally.
Comment #28
gstivanin CreditAttribution: gstivanin at CI&T commentedHaving the same issue on core 10.1.0 and patch #19 it's not applying, so rerolling this patch to apply on 10.1.0