@@ -4,6 +4,7 @@ from lightbug_http.strings import NetworkType
44from lightbug_http.utils import ByteReader
55from lightbug_http.net import NoTLSListener, default_buffer_size, NoTLSListener, SysConnection, SysNet
66from lightbug_http.http import HTTPRequest, encode
7+ from lightbug_http.http.common_response import InternalError
78from lightbug_http.uri import URI
89from lightbug_http.header import Headers
910from lightbug_http.service import HTTPService
@@ -119,7 +120,7 @@ struct Server:
119120 concurrency = DefaultConcurrency
120121 return concurrency
121122
122- fn listen_and_serve [T : HTTPService](inout self , address : String, inout handler : T) raises -> None :
123+ fn listen_and_serve [T : HTTPService](inout self , address : String, inout handler : T) raises :
123124 """
124125 Listen for incoming connections and serve HTTP requests.
125126
@@ -132,7 +133,7 @@ struct Server:
132133 _ = self .set_address(address)
133134 self .serve(listener, handler)
134135
135- fn serve [T : HTTPService](inout self , ln : NoTLSListener, inout handler : T) raises -> None :
136+ fn serve [T : HTTPService](inout self , ln : NoTLSListener, inout handler : T) raises :
136137 """
137138 Serve HTTP requests.
138139
@@ -141,7 +142,7 @@ struct Server:
141142 handler : HTTPService - An object that handles incoming HTTP requests.
142143
143144 Raises:
144- If there is an error while serving requests.
145+ If there is an error while serving requests.
145146 """
146147 self .ln = ln
147148
@@ -158,7 +159,7 @@ struct Server:
158159 handler : HTTPService - An object that handles incoming HTTP requests.
159160
160161 Raises:
161- If there is an error while serving the connection.
162+ If there is an error while serving the connection.
162163 """
163164 var max_request_body_size = self .max_request_body_size()
164165 if max_request_body_size <= 0 :
@@ -177,7 +178,13 @@ struct Server:
177178
178179 var request = HTTPRequest.from_bytes(self .address(), max_request_body_size, b^ )
179180
180- var res = handler.func(request)
181+ var res : HTTPResponse
182+ try :
183+ res = handler.func(request)
184+ except :
185+ _ = conn.write(encode(InternalError()))
186+ conn.close()
187+ return
181188
182189 var close_connection = (not self .tcp_keep_alive) or request.connection_close()
183190
0 commit comments