From dad7e04ccfbc14bc2b9ed844c78b9bd2c7ccf6cc Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Wed, 28 Jun 2023 11:51:57 +0200 Subject: [PATCH] Exceptions - Added `DeserializationError` Deserializer - On error now throws `DeserializationError` exception --- source/jstruct/deserializer.d | 7 +++---- source/jstruct/exceptions.d | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/source/jstruct/deserializer.d b/source/jstruct/deserializer.d index 09781c5..ba4e709 100644 --- a/source/jstruct/deserializer.d +++ b/source/jstruct/deserializer.d @@ -4,7 +4,7 @@ module jstruct.deserializer; import std.json; -import jstruct.exceptions : SerializationError; +import jstruct.exceptions : DeserializationError; import std.traits : FieldTypeTuple, FieldNameTuple, isArray; /** @@ -191,8 +191,7 @@ public RecordType fromJSON(RecordType)(JSONValue jsonIn) } catch(JSONException e) { - // TOOD: Should be DEserialization error - throw new SerializationError(); + throw new DeserializationError(); } } @@ -287,7 +286,7 @@ unittest Person person = fromJSON!(Person)(json); assert(false); } - catch(SerializationError) + catch(DeserializationError) { assert(true); } diff --git a/source/jstruct/exceptions.d b/source/jstruct/exceptions.d index 9383d2d..113ec65 100644 --- a/source/jstruct/exceptions.d +++ b/source/jstruct/exceptions.d @@ -15,3 +15,11 @@ public final class SerializationError : JStructException super("Error serializing"); } } + +public final class DeserializationError : JStructException +{ + this() + { + super("Error deserializing"); + } +} \ No newline at end of file