Error: Call to a member function getStatusCode() on string in friendlycaptcha_captcha_validation() using local endpoint

Created on 15 April 2024, 3 months ago
Updated 1 May 2024, 2 months ago

Problem/Motivation

Error: Call to a member function getStatusCode() on string in friendlycaptcha_captcha_validation() (Zeile 166 in /web/modules/contrib/friendlycaptcha/friendlycaptcha.module).

I think it happens when using the new local endpoint.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This is because the friendlycaptcha_captcha_validation($solution, $response, $element, $form_state) method overrides the $response variable if it's NOT the local endpoint, and that response is later used for retrieving the response code for a logging message.

    That said, there are 2 items to resolve:

    1. A method variable should never be overridden, especially not with a value of a different type. For that, a different variable name should be used.
    2. The logger message should be different for local endpoint and others, since there are different context variables available for both.
  • Status changed to Needs review 3 months ago
  • 🇮🇳India Rajan Kumar@2026

    hii @Anybody

    this error "Error: Call to a member function getStatusCode() on string in friendlycaptcha_captcha_validation()" , handle by added code.

  • Status changed to Needs work 3 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    @Rajan Kumar@2026 could you please provide a MR instead of a patch and read the comment from #2? Doesn't seem to solve that correctly.

  • First commit to issue fork.
  • 🇩🇪Germany Grevil

    Fixed! And tested with both the local and global endpoint, on both successful and unsuccessful result, as well as invalid API key.

    Works great! :)
    We are currently constructing the error message, even if the result is successful, this could be seen as a point of improvement, but this way, we don't need to create another if else case after the successful result check.

    Please review!

  • Status changed to Needs review 3 months ago
  • 🇩🇪Germany Grevil

    It might also make sense to log the user, if the error appears, but since captcha is often used for login, we might get a lot of anonymous user logged, but it is still a possibility, while we are at it!

  • Status changed to Needs work 3 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @Grevil, commented! :)

  • Status changed to Needs review 3 months ago
  • 🇩🇪Germany Grevil

    Adjusted accordingly!

  • Status changed to RTBC 3 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Nice! :)

    Please tag a new release.

    • Grevil committed 773ca7b2 on 1.x
      Issue #3441129 by Grevil: Error: Call to a member function getStatusCode...
  • Status changed to Fixed 3 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024