diff --git a/src/TranslatorService.vala b/src/TranslatorService.vala index 65ac8f7..a1e3fa9 100644 --- a/src/TranslatorService.vala +++ b/src/TranslatorService.vala @@ -22,6 +22,7 @@ public class TranslateService : AsyncTaskExecuter { var data = new Gee.ArrayList(); if (root != null) { + this.CheckForError(root); var sentences = root.get_array_member("text"); if (sentences != null) { @@ -46,4 +47,11 @@ public class TranslateService : AsyncTaskExecuter { _text = text; Run(); } + + private void CheckForError(Json.Object response) throws TranslatorError { + if (response.has_member ("code") && response.has_member ("message")) { + string error_message = response.get_member("message").get_string(); + throw new TranslatorError.TranslatedVolumeExceeded(error_message); + } + } } diff --git a/src/utils/TranslatorError.vala b/src/utils/TranslatorError.vala index 1e66cc5..ffe3ff2 100644 --- a/src/utils/TranslatorError.vala +++ b/src/utils/TranslatorError.vala @@ -1,5 +1,6 @@ /// Exceptions public errordomain TranslatorError { /// No connection error - NoConnection; -} \ No newline at end of file + NoConnection, + TranslatedVolumeExceeded; +}