Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Catalyst Debugging questions, specific and general

by Cody Fendant (Hermit)
on Jun 13, 2022 at 08:25 UTC ( [id://11144707]=perlquestion: print w/replies, xml ) Need Help??

Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

I've got a legacy Catalyst app I'm working on, and it has a bug when a form is submitted. The controller basically looks like this

sub update { if(method is POST){ do something with an API redirect to /list/ } render a form }

So if we have a GET to that action, you see the form and you get to fill it out. If we have a POST then it talks to the API to update a database then rather than getting the form you go back to list mode, because everything should be done by then.

The GET works without a hitch, but the POST fails and I get an error screen.

I put some logging in the API call and got nothing logged. So I moved back up to the update method and tried to log what was happening inside that if(method is POST) block and got nothing logged there either.

Then I noticed that the browser's actually getting a 404 code when the POST request happens.

I'm pretty baffled at this point. Is there some logical reason why my update in the controller should be fine when requested with GET and return a 404 for a POST? Is there some kind of routing magic which has gone wrong?

I've got Catalyst's -DEBUG flag turned on and can see detailed logging only it doesn't help. It shows the post request being made with the right params, then it shows the error template being rendered.

What can I do to better investigate this kind of thing?

Replies are listed 'Best First'.
Re: Catalyst Debugging questions, specific and general
by 1nickt (Canon) on Jun 13, 2022 at 14:49 UTC

    "Then I noticed that the browser's actually getting a 404 code when the POST request happens."

    FWIW I see the same thing with Mojolicious when there's a syntax error somewhere and the route handling code won't compile.

    Hope this helps!


    The way forward always starts with a minimal test.
Re: Catalyst Debugging questions, specific and general
by stevieb (Canon) on Jun 13, 2022 at 14:45 UTC
    The controller basically looks like this

    Please don't show us what the code basically looks like in pseudo code. Show the actual broken code.

    So I moved back up to the update method and tried to log what was happening inside that if(method is POST) block and got nothing logged there either.

    Did you ensure that whatever you're calling when you refer to method is POST is actually returning something? Are you actually calling the proper method to check if it's 'POST'? We don't know, because all you've got is pseudo code.

    Did you actually check whether the update() function is being called?

    A 404 is page not found. Do you have a route set up to handle the request? It sounds like that may be your problem. In Dancer2, you can specify a route type when defining a route:

    any ['get', 'post'] => '/' => sub { ... post '/garage_update' => sub {

    ...etc. If a 'get' request comes in for /garage_update, it'll fail. The / route accepts both GET and POST. I don't know if Catalyst does things like this though.

      I realise it's unhelpful to show pseudo-code but sure you realise it's equally unhelpful to tell me how to do routing in a completely different framework.

      To answer your questions:

      Did you ensure that whatever you're calling when you refer to method is POST is actually returning something?

      Yes, but also if it wasn't, it would continue as if it was a GET and not have the error. The routing is definitely working for GET.

      Did you actually check whether the update() function is being called?

      It must be being called or I wouldn't be seeing the form on a GET request.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11144707]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2024-04-18 16:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found