SaturnFramework / Saturn

Opinionated, web development framework for F# which implements the server-side, functional MVC pattern
https://saturnframework.org
MIT License
707 stars 108 forks source link

Template needs to be updated error_handler no longer valid in router #244

Open MicaelMor opened 4 years ago

MicaelMor commented 4 years ago

Hi,

I believe I have found an error with the template obtained using these https://saturnframework.org//tutorials/how-to-start.html instructions, in the apiRouter and api pipeline which are commented out.

The commented out apiRouter uses "error_handler", yet "error_handler" doesn't seem to be usable in a router computation expression, instead from what I have been able to understand (just started using saturn) it should be a "not_found_handler" like with the browserRouter.

There is also a slight improvement that could be made to this template, which is removing the extra space between the "//" characters and the actual code, since when using say CTRL+K+U in Visual Studio to remove the comment characters, it removes only the "//" leaving the extra single space character, this causes an error in the code because the these 2 functions aren't spaced the same as all the others. The same is true for the commented out line "// forward "/api" apiRouter", although in that specific case the error will be easier to spot (either way it is an easy fix IMO).

I could be mistaken about the "error_handler" thing since I am new to this (haven't even figured out how to consume an API from a client with json), so if there is a better substitute than "not_found_handler" please let me know.

Thank you.

Krzysztof-Cieslak commented 4 years ago

Hey, for consuming JSON API with the client - check out https://github.com/SaturnFramework/Saturn/issues/225. We set up some additional checks by default in the template so you need to be sure you pass correct headers.

And yes error_handler got replaced by not_found_handler in some previous version.

MicaelMor commented 4 years ago

Hi,

Thanks for the reply, yeah I had added "plug acceptJson" since I had previously used json with Saturn on a SAFE sample project and saw that the api in that sample had that line. My issue was that I was trying to use Thoth for it, and Thoth Fetch works with promises, and since my project doesn't use fable I couldn't use that, it was only now that I realized the SAFE sample project I was checking had replaced the json serializer of Giraffe with Toth by using the "use_json_serializer", so I should have ofc been using newtonsoft.json or another non fable json serializer instead.

Still need to check the gRpcSample project since for the purposes of using an F# client and an F# Saturn server, the communication by those means is likely to be smoother than passing json around.

Anyway to the topic of this issue, I have created a project of the template and committed the changes that would need to happen to fix it https://github.com/MicaelMor/SaturnSample/commit/f62894f1e77d6ecb5263089d4fa38509fe5209dc if that makes it any easier.

Thank you.