jk
08/14/2017, 2:08 PMmissingParamError
and incorrectPassword
, and what the similarity/differences between them are?davidase
08/14/2017, 2:10 PMobject Errors {
fun missingParam(req: Request, res: Response)
= generalError(req, res, 400, "missing-param")
fun invalidPhone(req: Request, res: Response)
= generalError(req, res, 400, "invalid-phone")
fun incorrectPin(req: Request, res: Response)
= generalError(req, res, 400, "incorrect-pin")
fun badRequest(req: Request, res: Response)
= generalError(req, res, 400, "general-error")
}
fun generalError(req: Request, res: Response, status: Int, error: String): String {
return res.redirectTo(req.pathInfo() + "?" + error)
}
generalError()
, logging etc)jk
08/14/2017, 2:19 PMrequest
, and response
come from when you call missingParamError(request, response)
? Is there an enclosing class you can make the receiver?davidase
08/14/2017, 2:20 PMobject Controller {
fun verifyPhone(req: Request, res: Response): String {
...
}
}
jk
08/14/2017, 2:22 PMRequest
or Response
without using a closure, but then you will lose the reusability so wouldn't be any use to youdavidase
08/14/2017, 2:23 PMjk
08/14/2017, 2:36 PMdata class ReqResp(val req: Request, val res: Response)
fun verifyPhone(req: Request, res: Response) {
handle(req, res) {
// do your handling code
// else
error("missing-param")
}
}
fun handle(req: Request, res: Response, handle:ReqResp.() -> Unit) {
ReqResp(req, res).handle()
}
fun ReqResp.error(error: String) {
res.redirectTo(req.pathInfo() + "?" + error)
}
davidase
08/15/2017, 7:32 AMjk
08/15/2017, 8:41 AMhandle
functions it might be more palatable