Skip to content

reactive: Reactive types must support side-effect handlers #3486

@hidemikimura

Description

@hidemikimura

It seems that something is being sent after the response is sent with Context.send() in CompletionStage.
Can the process here in io.jooby.internal.handler.apply() be changed?

      } else if (result instanceof CompletionStage future) {
        future.whenComplete(
            (value, x) -> {
              // Add the following if statement
              if (ctx.isResponseStarted()) {
                return;
              }
              try {
                Route.After after = ctx.getRoute().getAfter();
                if (after != null) {
                  // run after:
                  after.apply(ctx, value, unwrap((Throwable) x));
                }
                if (x != null) {
                  Throwable exception = unwrap((Throwable) x);
                  ctx.sendError(exception);
                } else {
                  ctx.render(value);
                }
              } catch (Throwable cause) {
                ctx.sendError(cause);
              }
            });
        // Return context to mark as handled
        return ctx;
      }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions