Install some basic error handling in Dispatch.
[jrw.git] / src / jrw / Dispatch.java
CommitLineData
3e20c35c
FT
1package jrw;
2
3import java.util.*;
88db3536
FT
4import java.io.*;
5import jrw.resp.*;
3e20c35c 6
d3d92d6c
FT
7public class Dispatch {
8 public static Map<Object, Object> handle(Handler handler, Request req) {
4e6705bd
FT
9 try(Environment.Frame f = new Environment().frame()) {
10 while(true) {
11 try {
12 return(handler.handle(req));
13 } catch(Restart r) {
14 handler = r;
88db3536
FT
15 } catch(Throwable t) {
16 t.printStackTrace((PrintStream)req.env.get("jagi.errors"));
17 handler = new jrw.resp.HttpError(500);
4e6705bd 18 }
3e20c35c
FT
19 }
20 }
21 }
22}