Slim 3 - Unsupported HTTP Method

Hello,

I having quite a trouble in handling this error:

Fatal error: Uncaught InvalidArgumentException: Unsupported HTTP method "COPY" provided in /home/u866020361/public_html/ruapi/libs/Slim/Slim/Http/Request.php:327

Stack trace:

/home/u866020361/public_html/ruapi/libs/Slim/Slim/Http/Request.php(179): Slim\Http\Request->filterMethod(‘COPY’)

/home/u866020361/public_html/ruapi/libs/Slim/Slim/Http/Request.php(146): Slim\Http\Request->__construct(‘COPY’, Object(Slim\Http\Uri), Object(Slim\Http\Headers), Array, Array, Object(Slim\Http\RequestBody), Array)

/home/u866020361/public_html/ruapi/libs/Slim/Slim/DefaultServicesProvider.php(61): Slim\Http\Request::createFromEnvironment(Object(Slim\Http\Environment))

/home/u866020361/public_html/ruapi/libs/Slim/vendor/pimple/pimple/src/Pimple/Container.php(113): Slim\DefaultServicesProvider->Slim{closure}(Object(Slim\Container))

/home/u866020361/public_html/ruapi/libs/Slim/Slim/Container.php(125): Pimple\Container->offsetGet(‘request’)

/home/u866020361/public_html/ruapi/libs/Slim/Slim/App.php(295): Slim\Container->get('re in

/home/u866020361/public_html/ruapi/libs/Slim/Slim/Http/Request.php on line 327

I have a route and I was testing if the notAllowedHandler works for all kinds of HTTP Methods that are not mapped in my routings and got this Exception instead.

The common ones: GET, POST, PUT, DELETE, OPTIONS works fine with the Handler.

The problem is other types of HTTP Methods like HEAD, COPY, LINK … etc are giving me an Exception instead of being solved by the Handler itself.

if I have only one method to the route, GET user/login and make a request to COPY user/login the application stops and launches an Exception instead of being handled by the Handler.

What should I do to solve this ?

I want that all HTTP methods that are not into my routes goes into the Handler.

Thanks.

Have you tried $app->any(‘routeGoesHere’, function($request, $response){what to do, what to do}); ?

@lektrikpuke

The thing is that I don’t want to map those Routes. I just want to catch them with the default notAllowedHandler whenever that Route Method is not mapped into my Routes and its being called.

If I just have GET operations, whenever someone try to call that route, lets say with COPY Method, it should’ve been catched by the notAllowedHandler but instead it gives me a Fatal Error inside Slim Framework and I don’t know how to Handle that InvalidArgumentException.

I can’t be the only one having this issue.

I have solved this by creating a handler between the Instantiation of Slim Application and $app->run().

I’ve put on my handler its own error_handler and if nothing goes wrong with $app->run() it passes the error handling to Slim.

That way I can catch all Errors and Exceptions before the error handling on Slim begins to catch.