Catch Exception in a logger
This commit is contained in:
parent
0e65f6648b
commit
5be25735ae
2 changed files with 14 additions and 3 deletions
|
@ -29,14 +29,17 @@ public class Client<U extends User> extends Thread{
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
}catch(InvalidJwtException e){
|
}catch(InvalidJwtException e){
|
||||||
|
this.router.getExceptionLogger().setValue(e);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
this.router.getExceptionLogger().setValue(e);
|
||||||
if(context != null && context.getResponseCode() == 0){
|
if(context != null && context.getResponseCode() == 0){
|
||||||
try{
|
try{
|
||||||
context.response(500);
|
context.response(500);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
}catch(Exception ex){}
|
}catch(Exception ex){
|
||||||
|
this.router.getExceptionLogger().setValue(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(context != null) router.getLogger().setValue(context);
|
if(context != null) router.getLogger().setValue(context);
|
||||||
|
@ -53,7 +56,9 @@ public class Client<U extends User> extends Thread{
|
||||||
writer.response(401, this.router.getDefaultHeaders(type));
|
writer.response(401, this.router.getDefaultHeaders(type));
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
}catch(Exception ex){}
|
}catch(Exception ex){
|
||||||
|
this.router.getExceptionLogger().setValue(ex);
|
||||||
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class Router<U extends User>{
|
||||||
}
|
}
|
||||||
|
|
||||||
private Locker<Context> logger;
|
private Locker<Context> logger;
|
||||||
|
private Locker<Exception> exceptions;
|
||||||
private RouteMapper<U>[] mappers;
|
private RouteMapper<U>[] mappers;
|
||||||
private List<RouteInterceptor> interceptors;
|
private List<RouteInterceptor> interceptors;
|
||||||
private Response noFileFound;
|
private Response noFileFound;
|
||||||
|
@ -42,6 +43,7 @@ public class Router<U extends User>{
|
||||||
|
|
||||||
public Router() throws Exception{
|
public Router() throws Exception{
|
||||||
this.logger = new Locker<>();
|
this.logger = new Locker<>();
|
||||||
|
this.exceptions = new Locker<>();
|
||||||
int types = RequestType.values().length;
|
int types = RequestType.values().length;
|
||||||
this.mappers = new RouteMapper[types];
|
this.mappers = new RouteMapper[types];
|
||||||
this.interceptors = new ArrayList<>();
|
this.interceptors = new ArrayList<>();
|
||||||
|
@ -142,6 +144,10 @@ public class Router<U extends User>{
|
||||||
return this.logger;
|
return this.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Locker<Exception> getExceptionLogger(){
|
||||||
|
return this.exceptions;
|
||||||
|
}
|
||||||
|
|
||||||
public void listen(int port, boolean ssl) throws Exception{
|
public void listen(int port, boolean ssl) throws Exception{
|
||||||
if (ssl) { // Not needed with the use of a proxy
|
if (ssl) { // Not needed with the use of a proxy
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Reference in a new issue