Athou / lapinstance

WoW Classic raid management and discord integration for Les Lapins de Lumière
http://www.loots.fr/
5 stars 2 forks source link

Error handling #5

Open Athou opened 4 years ago

Athou commented 4 years ago

When the backend returns a specific error and not a generic one, display a better message in the client.

kedbirhan commented 2 years ago

Hi @Athou I was integrating spring backend to a react front end. i am serving the react frontend from the spring backend like lapInstance. but when a user refreshes a page, 404 error is shown instead of reloading the page. is there a way I can prevent that?. I searched your backend implementation but I could not find any configurations. Thanks in Advance

Athou commented 2 years ago

Very difficult without seeing your code. Are you using react-router? If so, you probably need to use a hash router like this https://github.com/Athou/lapinstance/blob/master/client/src/App.tsx#L3

kedbirhan commented 2 years ago

@Athou yes, I am using react-router. I did change the router to hash-router as you suggested and it worked without showing the dreaded 404 error. Thanks!

kedbirhan commented 1 year ago

HI @Athou I had an idea about using straight BrowserRouter instead of HashRouter that works on refresh. My idea is to prepend the UI URLs shown in the browser with "ui" or "app" so we can differentiate it from the restful endpoint. This allows us to refresh the page without getting a Page Not Found error when the user manually refreshes the page. In addition, we will have to add in the backend to route any url that starts with "app" or "ui" to index.html as shown in the code below.

the reason is having hash routing doesn't look clean and its also not recommended. I have tried it in this project and it works fine. let me know if you want me to make a pull request.

@Configuration
public class WebConfiguration implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/app/**").setViewName("forward:/index.html");
    }
}