Error in how the slim framework customizes the request method

for example, the POST request interface is specified, but a request from GET will report an error as shown in the following figure

so how do you customize the returned errors? For example,
{"error": "Method not allowed"}

is returned.
Mar.01,2021

// notAllowedHandler
$container['notAllowedHandler'] = function ()
{
    return function ($req, $res, $allowMethod) {
        return $res->withJson([
            "status" => 0,
            "info" => "",
            "data" => $allowMethod
        ]);
    };
};
Menu