Skip to content

Commit c6dfa0d

Browse files
committed
Allow sub interface accessors to throw to signal general unavailability.
This enables throwing an exception from a sub interface accessor (e.g. HTTPStatusException with notFound) to control at runtime whether that sub interface is available. Note that a sub interface cannot become available after it has initially thrown an exception, so this is not meant to be a dynamic facility.
1 parent 6fd439f commit c6dfa0d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

web/vibe/web/rest.d

+12-2
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,20 @@ URLRouter registerRestInterface(TImpl)(URLRouter router, TImpl instance, RestInt
426426
alias R = ReturnType!ovrld;
427427

428428
static if (isInstanceOf!(Collection, R)) {
429-
auto ret = __traits(getMember, instance, fname)(R.ParentIDs.init);
429+
typeof(__traits(getMember, instance, fname)(R.ParentIDs.init)) ret;
430+
try ret = __traits(getMember, instance, fname)(R.ParentIDs.init);
431+
catch (Exception e) {
432+
logDiagnostic("Collection interface accessor %s.%s has thrown, skipping route registration: %s", TImpl.stringof, fname, e.msg);
433+
continue;
434+
}
430435
router.registerRestInterface!(R.Interface)(ret.m_interface, intf.subInterfaces[i].settings);
431436
} else {
432-
auto ret = __traits(getMember, instance, fname)();
437+
typeof(__traits(getMember, instance, fname)()) ret;
438+
try ret = __traits(getMember, instance, fname)();
439+
catch (Exception e) {
440+
logDiagnostic("Interface accessor %s.%s has thrown, skipping route registration: %s", TImpl.stringof, fname, e.msg);
441+
continue;
442+
}
433443
router.registerRestInterface!R(ret, intf.subInterfaces[i].settings);
434444
}
435445
}

0 commit comments

Comments
 (0)