Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning HttpResponse.redirect doesn't redirect but causes View crash #360

Open
Brutus5000 opened this issue Mar 4, 2022 · 1 comment · May be fixed by #361
Open

Returning HttpResponse.redirect doesn't redirect but causes View crash #360

Brutus5000 opened this issue Mar 4, 2022 · 1 comment · May be fixed by #361

Comments

@Brutus5000
Copy link

Expected Behavior

If something goes wrong in my call I use a HttpResponse.redirect to redirect to a dedicated error page.

Code example:

    @View("oauth2/login")
    @Get("/login")
    fun showLogin(
        @QueryValue("login_challenge") challenge: String,
        @QueryValue("loginFailed") loginFailed: Any?,
        @QueryValue("loginThrottled") loginThrottled: Any?,
    ): Mono<MutableHttpResponse<LoginResponse>> = hydraService.getLoginRequest(challenge)
        .map {
            HttpResponse.ok(
                LoginResponse(
                    properties.passwordResetUrl,
                    properties.registerAccountUrl,
                    loginFailed != null,
                    loginThrottled != null,
                    LoginForm(challenge = challenge)
                )
            )
        }.onErrorResume { error ->
            LOG.debug("Getting login request from Hydra failed for login challenge $challenge", error)
            HttpResponse.redirect<LoginResponse>(URI.create(LOGIN_TECHNICAL_ERROR_ROUTE)).toMono()
        }

Actual Behaviour

Instead of redirecting the user, Micronaut attempts to render the view (in my case Thymeleaf) without a body, causing errors in the view due to missing variables. This leads to no response to the user at all - not even an internal server error (not sure if this is a separate bug).

The ViewsFilter class seems to have no handling for redirects.

Steps To Reproduce

  1. Create a simple @Controller with Get and a View.
  2. Create a view and use some variables there
  3. Return a HttpResponse.redirect
  4. Call the endpoint

Environment Information

  • Arch Linux
  • JDK 17
  • Kotlin 1.6

Example Application

No response

Version

3.3.3

Brutus5000 added a commit to Brutus5000/micronaut-views that referenced this issue Mar 4, 2022
Fixes micronaut-projects#360
Instead of passing a missing body to the view do an early exit if a redirect is encountered.
Brutus5000 added a commit to Brutus5000/micronaut-views that referenced this issue Mar 4, 2022
Fixes micronaut-projects#360
Instead of passing a missing body to the view do an early exit if a redirect is encountered.
@Brutus5000 Brutus5000 linked a pull request Mar 4, 2022 that will close this issue
sdelamo added a commit to Brutus5000/micronaut-views that referenced this issue Jul 18, 2022
@rlconst
Copy link

rlconst commented Sep 8, 2024

Still valid for 4.5.0 and thymeleaf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants