In error case SetLocale Plug even not started, route error stopped it.
Actually I fix this error by moving plug MyApp.Plugs.SetLocale line from the routes to endpoint.ex above the plug Tiberis.Router line, now all works fine, but it still interesting for me.
Not able to test running it yet (maybe tomorrow), but one immediate possible issue I see is at: https://github.com/TakteS/rotes_test/blob/master/lib/routes_test/plugs/set_locale.ex#L7
Specifically it is calling for a redirect, but then it is still being passed up the line and handled as a normal call. And since here: https://github.com/TakteS/rotes_test/blob/master/web/router.ex#L10
It is being set in the global browser pipeline then it is going to try to redirect every single time. In your plug you should probably test if it is already on a valid locale path and if so then pass on, else call redirect to a valid path then maybe halt() the plug pipeline so your redirect is done (that might prevent the redirect from running if it is just halted outright, give it a try?).
An initial curiosity, browsers already give a locale in their headers, like mine sends Accept-Language:en-US,en;q=0.8 on every request since it only accepts “en-US” and “en”, in that order of priority. Why not do away with the entire locale routing and instead use the locale the browser supplies (they all should do) defaulting to ‘en’ or so?
At the very least you can do default locale routing based on the headers too if you want to keep the path style.
If you are using Gettext then you can get a valid locale list from it, including translations through it.
But yeah, at the very least the current plug looks incorrect as it will cause a redirect on every request (which may get overridden by pages doing their own thing). You can always detect the :locale in the controller on the path and if not a valid one then prepend /en to the path then re-direct too, no plug needed then either.
Otherwise I can try to test this tomorrow, please message again here to remind me. ^.^
It is just for example. In the real SetLocale Plug, of course,
redirecting work only if you do request without locale in other cases
plug just return a conn. But my example is enough for check how it work,
when you call /test/another, the plug is not run because phoenix throw an
error. Therefore I think that it isn’t my plug logic trouble, instead it is trouble with routing or more probably with my approach