HTTP types: headers, status codes, methods, bodies, MIME types
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

http: Json.to_string_exn -> Json.to_string (exn form dropped, bare form raises)

Callers of the old [Json.to_string_exn] now use the bare [Json.to_string]
which raises [Json.exception-Error] on encoder failure (codec bug).

+9 -9
+3 -3
lib/body.ml
··· 56 56 (* For simple JSON encoding, we just take a Json.t value and encode it *) 57 57 let json (json_value : Json.t) = 58 58 let content = 59 - try Json.to_string_exn ~format:Json.Minify Json.Codec.Value.t json_value 59 + try Json.Value.to_string ~format:Json.Minify json_value 60 60 with Json.Error e -> json_encoding_error e 61 61 in 62 62 String { content; mime = Mime.json } ··· 64 64 (* Typed JSON encoding using a Json.codec codec *) 65 65 let jsonv (type a) (codec : a Json.codec) (value : a) = 66 66 let content = 67 - try Json.to_string_exn ~format:Json.Minify codec value 67 + try Json.to_string ~format:Json.Minify codec value 68 68 with Json.Error e -> json_encoding_error e 69 69 in 70 70 String { content; mime = Mime.json } ··· 89 89 let json_stream_source_create json_value = 90 90 (* Encode the entire JSON value to string with minified format *) 91 91 let content = 92 - try Json.to_string_exn ~format:Json.Minify Json.Codec.Value.t json_value 92 + try Json.Value.to_string ~format:Json.Minify json_value 93 93 with Json.Error e -> json_encoding_error e 94 94 in 95 95 let t = { Json_stream_source.content; offset = 0 } in
+2 -2
lib/body.mli
··· 75 75 (** {1 Convenience Constructors} *) 76 76 77 77 val json : Json.t -> t 78 - (** [json value] creates a JSON body from a Json.t value. The value 79 - is encoded to a JSON string with Content-Type: application/json. 78 + (** [json value] creates a JSON body from a Json.t value. The value is encoded 79 + to a JSON string with Content-Type: application/json. 80 80 81 81 Example: 82 82 {[
+1 -1
lib/response.ml
··· 161 161 162 162 let json t = 163 163 let body_str = text t in 164 - try Json.of_string_exn Json.Codec.Value.t body_str 164 + try Json.Value.of_string_exn body_str 165 165 with Json.Error e -> 166 166 let preview = 167 167 if String.length body_str > 200 then String.sub body_str 0 200
+3 -3
test/test_huri.ml
··· 11 11 12 12 let test_jsont_roundtrip_simple () = 13 13 let uri = Uri.of_string "https://example.com" in 14 - let json_str = Json.to_string_exn ~format:Json.Minify Huri.jsont uri in 14 + let json_str = Json.to_string ~format:Json.Minify Huri.jsont uri in 15 15 let uri' = Json.of_string_exn Huri.jsont json_str in 16 16 Alcotest.(check string) "roundtrip" (Uri.to_string uri) (Uri.to_string uri') 17 17 18 18 let test_jsont_roundtrip_complex () = 19 19 let uri = Uri.of_string "http://user:pass@host:8080/path?q=1#frag" in 20 - let json_str = Json.to_string_exn ~format:Json.Minify Huri.jsont uri in 20 + let json_str = Json.to_string ~format:Json.Minify Huri.jsont uri in 21 21 let uri' = Json.of_string_exn Huri.jsont json_str in 22 22 Alcotest.(check string) 23 23 "roundtrip complex" (Uri.to_string uri) (Uri.to_string uri') 24 24 25 25 let test_jsont_encodes_as_string () = 26 26 let uri = Uri.of_string "https://example.com" in 27 - let json_str = Json.to_string_exn ~format:Json.Minify Huri.jsont uri in 27 + let json_str = Json.to_string ~format:Json.Minify Huri.jsont uri in 28 28 Alcotest.(check bool) 29 29 "starts with quote" true 30 30 (String.length json_str > 0 && json_str.[0] = '"');