Skip to content

Commit

Permalink
Catch parse errors and hand them to error_handler
Browse files Browse the repository at this point in the history
refs #18
  • Loading branch information
anmonteiro committed Apr 23, 2019
1 parent a1bc4b9 commit f078446
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,17 @@ module Reader = struct
ignore (read_with_more t Bigstringaf.empty ~off:0 ~len:0 Complete : int);
;;

let is_parse_failure t =
match t.parse_state with
| Fail _ -> true
| _ -> false

let next t =
match t.parse_state with
| Done ->
if t.closed
then `Close
else `Read
| Fail _ -> `Close
| Fail failure -> `Error failure
| Partial _ -> `Read
end
3 changes: 2 additions & 1 deletion lib/server_connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ let set_error_and_handle ?request t error =
t.error_handler ?request error (fun headers ->
Writer.write_response writer (Response.create ~headers status);
Body.of_faraday (Writer.faraday writer));
shutdown_writer t;
end

let report_exn t exn =
Expand All @@ -210,7 +211,7 @@ let advance_request_queue_if_necessary t =
else if not (Reqd.requires_input reqd)
then shutdown_reader t
end
end else if Reader.is_closed t.reader
end else if Reader.is_closed t.reader && (not (Reader.is_parse_failure t.reader))
then shutdown t

let _next_read_operation t =
Expand Down

0 comments on commit f078446

Please sign in to comment.