Mercurial Hosting > luan
changeset 1750:c7b3c327248a
webserver error handling
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 10 Jan 2023 22:42:47 -0700 |
parents | d1e7564a9ce5 |
children | 357daf580951 |
files | src/goodjava/webserver/Connection.java |
diffstat | 1 files changed, 15 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
diff -r d1e7564a9ce5 -r c7b3c327248a src/goodjava/webserver/Connection.java --- a/src/goodjava/webserver/Connection.java Mon Jan 09 22:06:06 2023 -0700 +++ b/src/goodjava/webserver/Connection.java Tue Jan 10 22:42:47 2023 -0700 @@ -72,7 +72,11 @@ int len = Integer.parseInt(lenStr); byte[] body = new byte[len]; size -= endOfHeader; - System.arraycopy(a,endOfHeader,body,0,size); + try { + System.arraycopy(a,endOfHeader,body,0,size); + } catch(ArrayIndexOutOfBoundsException e) { + throw new WrappedRuntimeException(e); + } while( size < len ) { int n = in.read(body,size,len-size); if( n == -1 ) { @@ -113,7 +117,7 @@ response = server.handler.handle(request); } catch(ParseException e) { - logger.warn("parse error\n"+request.rawHead.trim()+"\n",e); + logger.warn("parse error\n"+rawHead.trim()+"\n",e); String msg = e.toString(); if( contentType != null ) msg = "invalid content for content-type " + contentType + "\n" + msg; @@ -130,10 +134,19 @@ socket.close(); } catch(IOException e) { logger.info(rawHead.trim()+"\n",e); + } catch(WrappedRuntimeException wrapped) { + RuntimeException e = (RuntimeException)wrapped.getCause(); + logger.info(rawHead.trim()+"\n",e); + throw e; } catch(RuntimeException e) { logger.error(rawHead.trim()+"\n",e); throw e; } } + private static final class WrappedRuntimeException extends Exception { + WrappedRuntimeException(RuntimeException e) { + super(e); + } + } }