" ?"
, , , , , , , , .
@James , @matchish , . , . "", " ", , : " , , ". .
, , , DRY, "", , , . sendErrorCode
. , , , sendErrorCode
.
@James Thorpe, , , , sendErrorCode
, :
static async handleRequest(req) {
try {
let isAllowed = await checkIfIsAllowed(req);
if (!isAllowed) {
sendErrorCode(new ForbiddenException("You're not allowed to do that."));
return;
}
let result = await doSomething(req);
sendResult(result);
} catch(err) {
sendErrorCode(err);
}
}
- !isAllowed
. . , !isAllowed
, , , , , , isAllowed
.
@matchish doSomethingOnAllowedRequest
, , , , . DRY, , . , , , .