@@ -45,94 +45,94 @@ |
||
45 | 45 | use Sabre\DAV\Exception\ServiceUnavailable; |
46 | 46 | |
47 | 47 | class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { |
48 | - protected $nonFatalExceptions = [ |
|
49 | - NotAuthenticated::class => true, |
|
50 | - // If tokenauth can throw this exception (which is basically as |
|
51 | - // NotAuthenticated. So not fatal. |
|
52 | - PasswordLoginForbidden::class => true, |
|
53 | - // basically a NotAuthenticated |
|
54 | - InvalidSyncToken::class => true, |
|
55 | - // the sync client uses this to find out whether files exist, |
|
56 | - // so it is not always an error, log it as debug |
|
57 | - NotFound::class => true, |
|
58 | - // the sync client messed up their request |
|
59 | - // (e.g. propfind for tags with string instead of int) |
|
60 | - // so it is not always an error, log it as debug |
|
61 | - BadRequest::class => true, |
|
62 | - // this one mostly happens when the same file is uploaded at |
|
63 | - // exactly the same time from two clients, only one client |
|
64 | - // wins, the second one gets "Precondition failed" |
|
65 | - PreconditionFailed::class => true, |
|
66 | - // forbidden can be expected when trying to upload to |
|
67 | - // read-only folders for example |
|
68 | - Forbidden::class => true, |
|
69 | - // Happens when an external storage or federated share is temporarily |
|
70 | - // not available |
|
71 | - StorageNotAvailableException::class => true, |
|
72 | - // happens if some a client uses the wrong method for a given URL |
|
73 | - // the error message itself is visible on the client side anyways |
|
74 | - NotImplemented::class => true, |
|
75 | - // happens when the parent directory is not present (for example when a |
|
76 | - // move is done to a non-existent directory) |
|
77 | - Conflict::class => true, |
|
78 | - // happens when a certain method is not allowed to be called |
|
79 | - // for example creating a folder that already exists |
|
80 | - MethodNotAllowed::class => true, |
|
81 | - // A locked file is perfectly valid and can happen in various cases |
|
82 | - FileLocked::class => true, |
|
83 | - // An invalid range is requested |
|
84 | - RequestedRangeNotSatisfiable::class => true, |
|
85 | - ]; |
|
48 | + protected $nonFatalExceptions = [ |
|
49 | + NotAuthenticated::class => true, |
|
50 | + // If tokenauth can throw this exception (which is basically as |
|
51 | + // NotAuthenticated. So not fatal. |
|
52 | + PasswordLoginForbidden::class => true, |
|
53 | + // basically a NotAuthenticated |
|
54 | + InvalidSyncToken::class => true, |
|
55 | + // the sync client uses this to find out whether files exist, |
|
56 | + // so it is not always an error, log it as debug |
|
57 | + NotFound::class => true, |
|
58 | + // the sync client messed up their request |
|
59 | + // (e.g. propfind for tags with string instead of int) |
|
60 | + // so it is not always an error, log it as debug |
|
61 | + BadRequest::class => true, |
|
62 | + // this one mostly happens when the same file is uploaded at |
|
63 | + // exactly the same time from two clients, only one client |
|
64 | + // wins, the second one gets "Precondition failed" |
|
65 | + PreconditionFailed::class => true, |
|
66 | + // forbidden can be expected when trying to upload to |
|
67 | + // read-only folders for example |
|
68 | + Forbidden::class => true, |
|
69 | + // Happens when an external storage or federated share is temporarily |
|
70 | + // not available |
|
71 | + StorageNotAvailableException::class => true, |
|
72 | + // happens if some a client uses the wrong method for a given URL |
|
73 | + // the error message itself is visible on the client side anyways |
|
74 | + NotImplemented::class => true, |
|
75 | + // happens when the parent directory is not present (for example when a |
|
76 | + // move is done to a non-existent directory) |
|
77 | + Conflict::class => true, |
|
78 | + // happens when a certain method is not allowed to be called |
|
79 | + // for example creating a folder that already exists |
|
80 | + MethodNotAllowed::class => true, |
|
81 | + // A locked file is perfectly valid and can happen in various cases |
|
82 | + FileLocked::class => true, |
|
83 | + // An invalid range is requested |
|
84 | + RequestedRangeNotSatisfiable::class => true, |
|
85 | + ]; |
|
86 | 86 | |
87 | - /** @var string */ |
|
88 | - private $appName; |
|
87 | + /** @var string */ |
|
88 | + private $appName; |
|
89 | 89 | |
90 | - /** @var ILogger */ |
|
91 | - private $logger; |
|
90 | + /** @var ILogger */ |
|
91 | + private $logger; |
|
92 | 92 | |
93 | - /** |
|
94 | - * @param string $loggerAppName app name to use when logging |
|
95 | - * @param ILogger $logger |
|
96 | - */ |
|
97 | - public function __construct($loggerAppName, $logger) { |
|
98 | - $this->appName = $loggerAppName; |
|
99 | - $this->logger = $logger; |
|
100 | - } |
|
93 | + /** |
|
94 | + * @param string $loggerAppName app name to use when logging |
|
95 | + * @param ILogger $logger |
|
96 | + */ |
|
97 | + public function __construct($loggerAppName, $logger) { |
|
98 | + $this->appName = $loggerAppName; |
|
99 | + $this->logger = $logger; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * This initializes the plugin. |
|
104 | - * |
|
105 | - * This function is called by \Sabre\DAV\Server, after |
|
106 | - * addPlugin is called. |
|
107 | - * |
|
108 | - * This method should set up the required event subscriptions. |
|
109 | - * |
|
110 | - * @param \Sabre\DAV\Server $server |
|
111 | - * @return void |
|
112 | - */ |
|
113 | - public function initialize(\Sabre\DAV\Server $server) { |
|
114 | - $server->on('exception', [$this, 'logException'], 10); |
|
115 | - } |
|
102 | + /** |
|
103 | + * This initializes the plugin. |
|
104 | + * |
|
105 | + * This function is called by \Sabre\DAV\Server, after |
|
106 | + * addPlugin is called. |
|
107 | + * |
|
108 | + * This method should set up the required event subscriptions. |
|
109 | + * |
|
110 | + * @param \Sabre\DAV\Server $server |
|
111 | + * @return void |
|
112 | + */ |
|
113 | + public function initialize(\Sabre\DAV\Server $server) { |
|
114 | + $server->on('exception', [$this, 'logException'], 10); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Log exception |
|
119 | - * |
|
120 | - */ |
|
121 | - public function logException(\Throwable $ex) { |
|
122 | - $exceptionClass = get_class($ex); |
|
123 | - $level = ILogger::FATAL; |
|
124 | - if (isset($this->nonFatalExceptions[$exceptionClass]) || |
|
125 | - ( |
|
126 | - $exceptionClass === ServiceUnavailable::class && |
|
127 | - $ex->getMessage() === 'System in maintenance mode.' |
|
128 | - ) |
|
129 | - ) { |
|
130 | - $level = ILogger::DEBUG; |
|
131 | - } |
|
117 | + /** |
|
118 | + * Log exception |
|
119 | + * |
|
120 | + */ |
|
121 | + public function logException(\Throwable $ex) { |
|
122 | + $exceptionClass = get_class($ex); |
|
123 | + $level = ILogger::FATAL; |
|
124 | + if (isset($this->nonFatalExceptions[$exceptionClass]) || |
|
125 | + ( |
|
126 | + $exceptionClass === ServiceUnavailable::class && |
|
127 | + $ex->getMessage() === 'System in maintenance mode.' |
|
128 | + ) |
|
129 | + ) { |
|
130 | + $level = ILogger::DEBUG; |
|
131 | + } |
|
132 | 132 | |
133 | - $this->logger->logException($ex, [ |
|
134 | - 'app' => $this->appName, |
|
135 | - 'level' => $level, |
|
136 | - ]); |
|
137 | - } |
|
133 | + $this->logger->logException($ex, [ |
|
134 | + 'app' => $this->appName, |
|
135 | + 'level' => $level, |
|
136 | + ]); |
|
137 | + } |
|
138 | 138 | } |