summaryrefslogtreecommitdiff
path: root/classes/errors.php
diff options
context:
space:
mode:
authorAndrew Dolgov <noreply@fakecake.org>2022-01-13 13:59:36 +0300
committerAndrew Dolgov <noreply@fakecake.org>2022-01-13 13:59:36 +0300
commit304845f3807cc1021de1f29a35e2e3c370ff9882 (patch)
tree12206fcb33d26907254ee6adfe2bb20a553bbbca /classes/errors.php
parent8cf9c451dc1d5f3ed23ead40bee41592f7c07254 (diff)
parentf1607902e6953aa5c486157835105c0c8f08779f (diff)
Merge branch 'master' of git.fakecake.org:fox/tt-rss
Diffstat (limited to 'classes/errors.php')
-rw-r--r--classes/errors.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/classes/errors.php b/classes/errors.php
index 31be558cf..aa626d017 100644
--- a/classes/errors.php
+++ b/classes/errors.php
@@ -14,4 +14,27 @@ class Errors {
static function to_json(string $code, array $params = []): string {
return json_encode(["error" => ["code" => $code, "params" => $params]]);
}
+
+ static function libxml_last_error() : string {
+ $error = libxml_get_last_error();
+ $error_formatted = "";
+
+ if ($error) {
+ foreach (libxml_get_errors() as $error) {
+ if ($error->level == LIBXML_ERR_FATAL) {
+ // currently only the first error is reported
+ $error_formatted = self::format_libxml_error($error);
+ break;
+ }
+ }
+ }
+
+ return UConverter::transcode($error_formatted, 'UTF-8', 'UTF-8');
+ }
+
+ static function format_libxml_error(LibXMLError $error) : string {
+ return sprintf("LibXML error %s at line %d (column %d): %s",
+ $error->code, $error->line, $error->column,
+ $error->message);
+ }
}