From 26f720e44c0f2bfb10340ef6eafcb588ff34c456 Mon Sep 17 00:00:00 2001 From: Nathan Hadfield Date: Sat, 26 Jan 2019 01:50:54 -0700 Subject: [PATCH] add encode/2 function (in addition to encode!/2) --- lib/absinthe_sorting_codec.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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)