Skip to content

Text of MethodNotAllowedException is not properly rendered in the response body #4238

@SKevo18

Description

@SKevo18

Current Behavior

Given an URL and visiting it with unsupported method, for instance a GET request to https://demo.flarum.site/login produces message "An error occurred while trying to load this page.". Thrown here:

case Dispatcher::METHOD_NOT_ALLOWED:
throw new MethodNotAllowedException($method);

Flarum likely catches it and assumes it to be a generic error instead?

Steps to Reproduce

  1. Go to https://demo.flarum.site/login, https://demo.flarum.site/register or https://demo.flarum.site/global-logout, etc.
  2. Observe that the body has "An error occurred while trying to load this page."

Expected Behavior

The body says "Method not allowed." instead of "An error occurred while trying to load this page."

Screenshots

No response

Environment

  • Flarum version: 1.8.10
  • Website URL: https://demo.flarum.site/ (applicable on any Flarum installation)
  • Webserver: nginx
  • Hosting environment: shared
  • PHP version: 8.3.22
  • Browser: Firefox 142.0.1 (aarch64)

Output of php flarum info

No response

Possible Solution

Possibly: catch MethodNotAllowedException and render a body message, e. g. add handlers here(?)

// 405 Method Not Allowed
'method_not_allowed' => 405,
// 409 Conflict
'io_error' => 409,
// 429 Too Many Requests
'too_many_requests' => 429,
// 503 Service Unavailable
'maintenance' => 503,
];
});
$this->container->singleton('flarum.error.classes', function () {
return [
InvalidParameterException::class => 'invalid_parameter',
ModelNotFoundException::class => 'not_found',
];

Additional Context

Ref.: https://support.freeflarum.com/d/592/2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions