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.
This is being split off from #3035589
The issue originally came up because 406 errors weren't getting caught and handled correctly. This issue is to fix the logging aspect so that 4xx errors are no longer logged as exceptions.
How to reproduce:
wget 'http://your-testing.tld/node/1?_format=hal_json'
Check the logs and you'll see the exception logged.
Comment | File | Size | Author |
---|---|---|---|
#27 | 3039266-27.patch | 3.19 KB | joshua1234511 |
#22 | interdiff_13-22.txt | 1.91 KB | ravi.shankar |
#22 | 3039266-22.patch | 3.36 KB | ravi.shankar |
#17 | Before_patch.png | 28.36 KB | vikashsoni |
#14 | Screenshot 2020-07-13 at 10.41.33 PM.png | 46.91 KB | samiullah |
Comments
Comment #2
slip CreditAttribution: slip at Last Call Media commentedHere's a patch to fix this.
don't think we need the specific 404/403 logging so I removed it. I'm happy to add those back if for some reason putting them into separate logging types is useful.
I kept support for the on404/on403 style method calls in case removing that would be considered breaking backwards compatibility. Doesn't hurt to have it in any case imo.
Comment #3
slip CreditAttribution: slip at Last Call Media commentedSetting to needs work. I see there are references to the 'page not found' and 'access denied' logs. I'm thinking I'll add those back in and just make a generic fallback
Comment #5
Primsi CreditAttribution: Primsi commentedSome contrib modules rely on the logic provided by existing methods (see redirect_404)
I re-added them but kept the 4xx fallback.
Comment #6
Primsi CreditAttribution: Primsi commentedComment #7
BerdirComment #8
BerdirReroll for Drupal 9.
Comment #9
Primsi CreditAttribution: Primsi commentedAdding a test.
Comment #11
joshua1234511Reviewed the Patch #9
https://www.drupal.org/files/issues/2020-07-09/4xx-log-3039266-9.patch
Php 7.4 and Drupal core 9.1 4xx-log-3039266-9.patch
Comment #12
johnwebdev CreditAttribution: johnwebdev commenteds/that a/that
This doesn't seem right?
/s/that a/that
Maybe a blank line, and a comment to explain what we're doing here to trigger the exception. Doesn't necessarily need a comment, but we can at least separate the preparation for the test, and the trigger of the exception.
Comment #13
Primsi CreditAttribution: Primsi commentedThanks for the review. 3. should be correct, given that it's a fallback method for 4xx exceptions. Or did you mean something else?
Comment #14
samiullah CreditAttribution: samiullah at Salsa Digital commentedLooks good
I tested this manually
Before Applying the patch
1. Navigate to http://localhost:8888/drupal/node/1?_format=hal_json%27. (Replace localhost with ur site base url)
2. You should see site encountered error
3. Check DBlog
4. See latet php error
5. Now apply the latest patch given in #13
6. Repeat step 1 to 3
7. In dblog u should see 4xx error
This can be moved to RTBC
Comment #16
Krzysztof DomańskiRetested. https://www.drupal.org/pift-ci-job/1868692 It was a random test failure #2825845: DST-related test failures in FilterDateTimeTest.
Comment #17
vikashsoni CreditAttribution: vikashsoni as a volunteer and at Zyxware Technologies commentedApplied #13 patch Working fine showing 4xx error in recent log
Comment #18
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u at Zyxware Technologies commentedThe last patch works fine.
Before patch
After patch
RTBC
Comment #19
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u at Zyxware Technologies commentedComment #20
catchOne cs error to fix:
Comment #21
quietone CreditAttribution: quietone as a volunteer commentedI did a code review.
This type does not agree with the parameter declared in the function.
I think this can be changed so that the fallback method name is only generated when $possible_method does not exist. Also, tweaked the comment to make it read a bit better and wrap at 80 columns.
Lets be clear about what this does, "Tests that a 4xx errors are logged as a '4xx error'."
Change to "Create a uri that will cause a 406 error."
Add a comment above this line.
// Confirm that a php error was not logged and that a 4xx error was.
@uri is not used. Should it be?
Comment #22
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedHere I have addressed comment #20, #21.1, #21.3, #21.4, and #21.5.
Still needs work for #21.2 and #21.6
Comment #26
joshua1234511Updated the patch from #22
- Rerolled for 9.5.x
- Worked on the pending points from #21
Result:
Comment #27
joshua1234511Updated test
Comment #28
Chi CreditAttribution: Chi commentedDoesn't it duplicate #2828706: ExceptionLoggingSubscriber should not log HTTP 4XX errors using PHP logger channel?
Comment #32
quietone CreditAttribution: quietone at PreviousNext commentedI think Chi is right, that this is a duplicate of an earlier issue, #2828706: ExceptionLoggingSubscriber should not log HTTP 4XX errors using PHP logger channel.
I am closing this and moving credit.