I am implementing a fragment with a REST endpoint and I would like to display an error if the issue does not have any components. The button is called "MounaGenerate" and here is my implementation of the fragment below:

Here is my implementation of the REST endpoint:
package SuperFeature
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import javax.ws.rs.core.Response
import com.opensymphony.workflow.WorkflowException
@BaseScript CustomEndpointDelegate delegate
mounaGenerate(httpMethod: "GET", groups: ["jira-users"]) {
def log = Logger.getLogger("atlassian-jira.log")
def components = issue.components
log.warn("MOUNA COMPONENTS "+components)
if(components.empty) {
log.warn("MOUNA EMPTY")
throw new WorkflowException("Issue does not have components")
}
}
I am getting the following error on my log:
2023-09-05 14:30:09,456+0200 https-openssl-nio-443-exec-6 ERROR mouh 870x1330103x2 1ic193i 10.250.160.111 /rest/scriptrunner/latest/custom/mounaGenerate [c.o.s.r.rest.common.UserCustomScriptEndpoint] Script endpoint failed on method: GET mounaGenerate
2023-09-05 14:30:09,456+0200 https-openssl-nio-443-exec-6 ERROR mouh 870x1330103x2 1ic193i 10.250.160.111 /rest/scriptrunner/latest/custom/mounaGenerate [c.o.s.r.rest.common.UserCustomScriptEndpoint]
Ideally, I would like a new page to be shown like the following that says that there is an error because the issue does not have any components:

How can I do this?