joaotavora / snooze

Common Lisp RESTful web development
207 stars 23 forks source link

Defining the root route, debugging an internal server error #5

Closed vindarel closed 6 years ago

vindarel commented 6 years ago

Hello, After trying a bit Ningle and Caveman, Snooze looks sanier (straightforward mapping to query parameters, that sold me). I have two questions.

I didn't find how to define the root route. defroute takes a method name.

(defroute index (:get :text/*)
          (search-page))

and then defines the endpoints /index/. What if we just want / ? (only / is not possible, I tried :) SBCL freaks out)


I was going to give full details but first: how do you debug a 500 internal server error ? I tested each piece of my route in the repl, with fake data and all, but together it won't pass and I only get this straight error message. And it doesn't help to print "oh dear, it seems I've messed up" :) Also the browser returns a warning about bad encodings of this plain text error message. A bit disturbing. It is Hunchentoot's fault ?

Thanks !

joaotavora commented 6 years ago

Hello @vindarel and let me welcome you to the status of the first non-me user of snooze! Let me try to help you:

Your first question is easy to answer: have a look at the variable SNOOZE:*HOME-RESOURCE. If you set it to :index, that route will be served on \.

Your second question is also easy to answer, I think. To debug 500, you have several options:

(setf snooze:*catch-errors* :verbose)

This will print a backtrace to your browser. But you also have

(setf snooze:*catch-errors* nil)

This will let the error flow through snooze unfettered and possibly be caught by hunchentoot. But if you also

(setf hunchentoot:*catch-errors-p* nil)

Then possibly the your Lisp debugger (SLIME or SLY) will be invoked.

All of this information is written down in the form of the docstrings of the functions in snooze's api.lisp. I recomend you read these docstrings from beginning to end (it's not a very large file). Along with the tutorial, they are the best and only documentation I have.

Also the browser returns a warning about bad encodings of this plain text error message. A bit disturbing. It is Hunchentoot's fault ?

The third situation you describe is a bug in snooze probably, but I cant reproduce it. Nothing to be worried about I would say. Can you post a screenshot of firebug or chrome developer tools or attach the full HTTP 500 error response?

vindarel commented 6 years ago

OMG, that was quick and easy ! What a surprise :] These settings did the trick, and they're pretty convenient. So there is no need to use clack-errors, as it seems. Ok (but clack-errors gives a more polished look).

About the encoding error:

selection_195

selection_194

the response headers:

Date: Thu, 07 Dec 2017 11:57:38 GMT
Server: Hunchentoot 1.2.37
Keep-Alive: timeout=20
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

I did a quick survey and it shows that your users are at 98% satisfied. Congrats !

joaotavora commented 6 years ago

Regarding the content-type problem, It's probably hunchentoot which in my case is declaring it automatically Content-Type: text/plain; charset=utf-8 which is correct. I'm using hunchentoot 1.2.35 which version are you using?

Regardless snooze could and should override this to its proper value. I'll investigate a bit more.

Regarding clack-errors, I'll try to copy some of its polish for the "verbose" option.

I did a quick survey and it shows that your users are at 98% satisfied. Congrats !

What?

vindarel commented 6 years ago

What?

oh sorry. Since I'm the first non-you user that was a quick survey. TLDR; cool stuff :)


Another easy question: how would one do a redirection ? Maybe with a funcall or something. Didn't find, skimmed at the readme and api. If that's Clack's job I didn't find it in its doc either (very scarce). A redirect example would be useful.

joaotavora commented 6 years ago

oh sorry. Since I'm the first non-you user that was a quick survey. TLDR; cool stuff :)

lol, good one :man_facepalming: :rofl:

Another easy question: how would one do a redirection ? Maybe with a funcall or something. Didn't find, skimmed at the readme and api. If that's Clack's job I didn't find it in its doc either (very scarce). A redirect example would be useful.

Opened a new issue with the answer, hopefully. Try to open new issues for new problems, thanks.