Search in sources :

Example 1 with NotFoundException

use of org.webpieces.router.api.exceptions.NotFoundException in project webpieces by deanhiller.

the class RouteInvoker method invoke2.

public CompletableFuture<Void> invoke2(MatchResult result, RequestContext requestCtx, ResponseStreamer responseCb, ErrorRoutes errorRoutes) {
    //This makes us consistent with other NotFoundExceptions and without the cost of 
    //throwing an exception and filling in stack trace...
    //We could convert the exc. to FastException and override method so stack is not filled in but that
    //can get very annoying
    RouteMeta meta = result.getMeta();
    Route route = meta.getRoute();
    RouteType routeType = route.getRouteType();
    if (routeType == RouteType.NOT_FOUND) {
        CompletableFuture<Void> future = new CompletableFuture<Void>();
        future.completeExceptionally(new NotFoundException("route not found"));
        return future;
    }
    return invokeImpl(result, meta.getService222(), requestCtx, responseCb);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RouteType(org.webpieces.router.api.dto.RouteType) NotFoundException(org.webpieces.router.api.exceptions.NotFoundException)

Example 2 with NotFoundException

use of org.webpieces.router.api.exceptions.NotFoundException in project webpieces by deanhiller.

the class RouteInvoker method processNotFound.

public CompletableFuture<Void> processNotFound(ResponseStreamer responseCb, RequestContext requestCtx, NotFoundException e, ErrorRoutes errorRoutes, Object meta) {
    NotFoundException exc = (NotFoundException) e;
    NotFoundInfo notFoundInfo = errorRoutes.fetchNotfoundRoute(exc);
    RouteMeta notFoundResult = notFoundInfo.getResult();
    RouterRequest overridenRequest = notFoundInfo.getReq();
    RequestContext overridenCtx = new RequestContext(requestCtx.getValidation(), (FlashSub) requestCtx.getFlash(), requestCtx.getSession(), overridenRequest);
    //http 404...(unless an exception happens in calling this code and that then goes to 500)
    return notFound(notFoundResult, notFoundInfo.getService(), exc, overridenCtx, responseCb);
}
Also used : NotFoundException(org.webpieces.router.api.exceptions.NotFoundException) RequestContext(org.webpieces.ctx.api.RequestContext) RouterRequest(org.webpieces.ctx.api.RouterRequest)

Example 3 with NotFoundException

use of org.webpieces.router.api.exceptions.NotFoundException in project webpieces by deanhiller.

the class StaticFileReader method fetchFile.

private Path fetchFile(String msg, String fullFilePath) {
    Path file = Paths.get(fullFilePath);
    File f = file.toFile();
    if (!f.exists() || !f.isFile())
        throw new NotFoundException(msg + file + " was not found");
    return file;
}
Also used : Path(java.nio.file.Path) NotFoundException(org.webpieces.router.api.exceptions.NotFoundException) File(java.io.File)

Aggregations

NotFoundException (org.webpieces.router.api.exceptions.NotFoundException)3 File (java.io.File)1 Path (java.nio.file.Path)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 RequestContext (org.webpieces.ctx.api.RequestContext)1 RouterRequest (org.webpieces.ctx.api.RouterRequest)1 RouteType (org.webpieces.router.api.dto.RouteType)1