Safe URI decoding/encoding
srghma opened this issue · comments
Serhii Khoma commented
was implemented in #20 (comment)
does it make sense to introduce such change?
because right now it just unsafeThrowError
Nathan Faubion commented
I don't really want to add partiality to a printer, especially since the failure mode is so obscure. I'm inclined to just filter out things that don't encode.
Serhii Khoma commented
ok, this is possible
just want to confirm. You are for the 2d option:
- right now - fails silently with
unsafeThrowError
- we can - fail silently by omitting the
URIComponents
that cannot be encoded / decoded - we can - fail with an error
was
parse :: forall i o. RouteDuplex i o -> String -> Either Parser.RouteError o
parse (RouteDuplex _ dec) = Parser.run dec
-- | Renders a value of type `i` into a String representation of URI path,
-- | query and fragment (hash).
print :: forall i o. RouteDuplex i o -> i -> String
print (RouteDuplex enc _) = Printer.run <<< enc
now
data RouteParseError
= RouteParseError RouteError
| DecodeURIError String
parse :: forall i o. RouteDuplex i o -> String -> Either Parser.RouteParseError o
parse (RouteDuplex _ dec) = Parser.run dec
newtype PrintPathError = EncodeURIComponentError String
-- | Renders a value of type `i` into a String representation of URI path,
-- | query and fragment (hash).
print :: forall i o. RouteDuplex i o -> i -> Either PrintPathError String
print (RouteDuplex enc _) = Printer.run <<< enc