diff --git a/lib/absinthe_sorting_codec.ex b/lib/absinthe_sorting_codec.ex index 0e6ab7d..5c49829 100644 --- a/lib/absinthe_sorting_codec.ex +++ b/lib/absinthe_sorting_codec.ex @@ -25,10 +25,18 @@ defmodule AbsintheSortingCodec do Uses [Jason](https://github.com/michalmuskala/jason) for encoding into JSON. """ - def encode!(schema, opts \\ []) do + + def encode(schema, opts \\ []) do schema |> sorted_objects() - |> Jason.encode!(opts) + |> Jason.encode(opts) + end + + def encode!(schema, opts \\ []) do + case encode(schema, opts) do + {:ok, content} -> content + {:error, reason} -> raise reason + end end defp sorted_objects(value)