I have written a service I'm currently facing an issue where I want to stop the request cycle at a certain point and a return something to client side.
I have used methods like ctx.EndRequest()
ctx.StopExecution()
but it keeps execute until the handler method finishes.
if aff.Status != StatActive {
//Affiliate Not active exception
err := errors.NewAffiliateNotActiveError(ctx)
pc, fn, line, _ := runtime.Caller(1)
log.Printf("[error] in %s[%s:%d] %v", runtime.FuncForPC(pc).Name(), fn, line, err)
ctx.Write([]byte(err.Error()))
ctx.StopExecution()
}
Like above when that condition triggered I want to stop execution equivalent of a throw exception. How can I achieve that?
You need a return statement if you want the handler execution to stop.