From 33efe571e3e7ebd607e92345c2e94e7fd8ae27f0 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 2 Feb 2015 19:45:11 +0100 Subject: Rework api error handling Signed-off-by: Florian Pritz --- application/exceptions/ApiException.php | 30 +++++++++++++++++++++++++++ application/exceptions/PublicApiException.php | 10 +++++++++ 2 files changed, 40 insertions(+) create mode 100644 application/exceptions/ApiException.php create mode 100644 application/exceptions/PublicApiException.php (limited to 'application/exceptions') diff --git a/application/exceptions/ApiException.php b/application/exceptions/ApiException.php new file mode 100644 index 000000000..b288bbaa2 --- /dev/null +++ b/application/exceptions/ApiException.php @@ -0,0 +1,30 @@ +error_id = $error_id; + $this->data = $data; + } + + public function get_error_id() + { + return $this->error_id; + } + + public function get_data() + { + return $this->data; + } +} diff --git a/application/exceptions/PublicApiException.php b/application/exceptions/PublicApiException.php new file mode 100644 index 000000000..e7aa4360a --- /dev/null +++ b/application/exceptions/PublicApiException.php @@ -0,0 +1,10 @@ + Date: Tue, 3 Feb 2015 00:23:12 +0100 Subject: Rework error handling in upload validator Signed-off-by: Florian Pritz --- .../exceptions/FileUploadVerifyException.php | 23 ++++++++++++++++++++++ application/exceptions/PublicApiException.php | 4 ++++ application/exceptions/UserInputException.php | 10 ++++++++++ 3 files changed, 37 insertions(+) create mode 100644 application/exceptions/FileUploadVerifyException.php create mode 100644 application/exceptions/UserInputException.php (limited to 'application/exceptions') diff --git a/application/exceptions/FileUploadVerifyException.php b/application/exceptions/FileUploadVerifyException.php new file mode 100644 index 000000000..d091c1eab --- /dev/null +++ b/application/exceptions/FileUploadVerifyException.php @@ -0,0 +1,23 @@ +getMessage()."\n"; + $data = $this->get_data(); + $errors = array(); + + foreach ($data as $error) { + $errors[] = sprintf("%s: %s", $error["filename"], $error["message"]); + } + + $ret .= implode("\n", $errors); + return $ret; + } +} diff --git a/application/exceptions/PublicApiException.php b/application/exceptions/PublicApiException.php index e7aa4360a..d22309478 100644 --- a/application/exceptions/PublicApiException.php +++ b/application/exceptions/PublicApiException.php @@ -7,4 +7,8 @@ namespace exceptions; class PublicApiException extends ApiException { + public function __toString() + { + return $this->getMessage(); + } } diff --git a/application/exceptions/UserInputException.php b/application/exceptions/UserInputException.php new file mode 100644 index 000000000..150d0204b --- /dev/null +++ b/application/exceptions/UserInputException.php @@ -0,0 +1,10 @@ + Date: Tue, 3 Feb 2015 12:11:28 +0100 Subject: api: implement file/create_multipaste Signed-off-by: Florian Pritz --- .../exceptions/FileUploadVerifyException.php | 2 +- application/exceptions/VerifyException.php | 23 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 application/exceptions/VerifyException.php (limited to 'application/exceptions') diff --git a/application/exceptions/FileUploadVerifyException.php b/application/exceptions/FileUploadVerifyException.php index d091c1eab..5125e4822 100644 --- a/application/exceptions/FileUploadVerifyException.php +++ b/application/exceptions/FileUploadVerifyException.php @@ -6,7 +6,7 @@ */ namespace exceptions; -class FileUploadVerifyException extends UserInputException { +class FileUploadVerifyException extends VerifyException { public function __toString() { $ret = $this->getMessage()."\n"; diff --git a/application/exceptions/VerifyException.php b/application/exceptions/VerifyException.php new file mode 100644 index 000000000..0e9d8b93a --- /dev/null +++ b/application/exceptions/VerifyException.php @@ -0,0 +1,23 @@ +getMessage()."\n"; + $data = $this->get_data(); + $errors = array(); + + foreach ($data as $error) { + $errors[] = sprintf("%s: %s", $error["id"], $error["reason"]); + } + + $ret .= implode("\n", $errors); + return $ret; + } +} -- cgit v1.2.3-24-g4f1b From bcd7920b817b60df9b1b266118419e44c39900db Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 3 Feb 2015 13:59:59 +0100 Subject: generalize authentication handling Signed-off-by: Florian Pritz --- application/exceptions/ApiException.php | 5 +++++ .../exceptions/InsufficientPermissionsException.php | 14 ++++++++++++++ application/exceptions/NotAuthenticatedException.php | 14 ++++++++++++++ application/exceptions/UserInputException.php | 4 ++++ 4 files changed, 37 insertions(+) create mode 100644 application/exceptions/InsufficientPermissionsException.php create mode 100644 application/exceptions/NotAuthenticatedException.php (limited to 'application/exceptions') diff --git a/application/exceptions/ApiException.php b/application/exceptions/ApiException.php index b288bbaa2..b3b9decff 100644 --- a/application/exceptions/ApiException.php +++ b/application/exceptions/ApiException.php @@ -27,4 +27,9 @@ class ApiException extends \Exception { { return $this->data; } + + public function get_http_error_code() + { + return 500; + } } diff --git a/application/exceptions/InsufficientPermissionsException.php b/application/exceptions/InsufficientPermissionsException.php new file mode 100644 index 000000000..a036edf9d --- /dev/null +++ b/application/exceptions/InsufficientPermissionsException.php @@ -0,0 +1,14 @@ + Date: Tue, 3 Feb 2015 17:17:27 +0100 Subject: Use exceptions instead of show_error Signed-off-by: Florian Pritz --- application/exceptions/NotFoundException.php | 14 ++++++++++++++ application/exceptions/RequestTooBigException.php | 14 ++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 application/exceptions/NotFoundException.php create mode 100644 application/exceptions/RequestTooBigException.php (limited to 'application/exceptions') diff --git a/application/exceptions/NotFoundException.php b/application/exceptions/NotFoundException.php new file mode 100644 index 000000000..c4b9d1537 --- /dev/null +++ b/application/exceptions/NotFoundException.php @@ -0,0 +1,14 @@ +