blue-jay / blueprint

Blueprint for your next web application in Go.
https://blue-jay.github.io/
MIT License
481 stars 77 forks source link

Form Error is always: "An error occurred on the server. Please try again later." #53

Closed ghost closed 7 years ago

ghost commented 7 years ago

I always get "An error occurred on the server. Please try again later.". I think the right way would be to say something like: The email field is missing. It prints it in the server logs, but wouldn't that be a message the user wants to see? Hope you get what I mean.

josephspurrier commented 7 years ago

If your form is missing a value, then it will say a field is missing in the popup error message.

An example is in the Register form: https://github.com/blue-jay/blueprint/blob/master/controller/register/register.go#L36

You can see the FormValid method in Flight: https://github.com/blue-jay/blueprint/blob/master/lib/flight/flight.go#L103

If you get "an error occurred on the server" message, it means that something went wrong on the back end of the application like the database is unavailable. Do you have a specific example you'd like to go over?

vjey23 commented 7 years ago

I did encounter similar issue. It is because c.FlashError on https://github.com/blue-jay/blueprint/blob/master/controller/register/register.go#L37

passing correct error but https://github.com/blue-jay/blueprint/blob/master/lib/flight/flight.go#L139 is not using passed error. I replaced the "An error occurred on the server. Please try again later." with err string.

josephspurrier commented 7 years ago

I'm glad you replaced it with your error to fit your needs. Blueprint is supposed to be just a template that you can use in your projects. The Core library is pretty solid, but Blueprint is designed to be modified to fit your use case. You don't even have to use the libraries in Core, I find myself replacing libraries in Core as our projects mature, but it's definitely a solid jumping off point.

I'm going to leave my code the way it is so the user doesn't receive any confusing information on the front end. The actual error is logged for the admin to look at and debug: https://github.com/blue-jay/blueprint/blob/master/lib/flight/flight.go#L138

ghost commented 7 years ago

@josephspurrier When I installed blueprint and let a field empty, there was no error message like 'Field missing: ...', it was 'An error occured on the server...'.

josephspurrier commented 7 years ago

Which field on which screen?

ghost commented 7 years ago

When clicking on 'Create Account': 2017-02-01-090324_1920x1080_scrot When clicking on 'Login': 2017-02-01-090340_1920x1080_scrot

josephspurrier commented 7 years ago

What is the error in your CLI? The reason it failed should show there. Send the whole log from your console.

ghost commented 7 years ago

Console output:

2017-02-08 03:31:03 PM [::1]:42660 POST /login
flight.go:138: Field missing: email

When I add a note without content, I get the following error, that seems right: 2017-02-08-153230_1920x1080_scrot

In my opinion the error from the console should be shown in the frontend for the user to see what he has done wrong.

josephspurrier commented 7 years ago

Thanks for bringing this to my attention. There were two issues. Login and Register should have been using the Flight.FormValid function. Also, I created a new FlashErrorGeneric for errors off MySQL and other things that are not useful to the user.

https://github.com/blue-jay/blueprint/commit/46c382431f4e2a9fdaa552ccd63c8a93921de4a2