Skip to content

Commit a43c6f1

Browse files
committed
Error handler
1 parent 9ea0db1 commit a43c6f1

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

inc/hook.class.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use GuzzleHttp\Exception\BadResponseException;
4+
35
class PluginLibresignHook extends CommonDBTM
46
{
57
public static function itemUpdate(TicketValidation $ticket)
@@ -64,8 +66,8 @@ public static function preItemPurge(TicketValidation $ticket)
6466
{
6567
try {
6668
$iterator = self::getSignRequests([
67-
'ticket_id' => $ticket->input['tickets_id'],
68-
'user_id' => $ticket->input['users_id_validate']
69+
'ticket_id' => $ticket->fields['tickets_id'],
70+
'user_id' => $ticket->fields['users_id_validate']
6971
]);
7072
if (!count($iterator)) {
7173
throw new Exception(__('No signer found'));
@@ -95,15 +97,24 @@ private static function requestDeleteSigner(string $uuid, string $email)
9597

9698
include_once(Plugin::getPhpDir('libresign').'/inc/httpclient.class.php');
9799
$client = new PluginLibresignHttpclient();
98-
$client->request('DELETE', $config->fields['nextcloud_url'] . '/signature', [
99-
'json' => [
100-
'uuid' => $uuid,
101-
'users' => [
102-
['email' => $email]
103-
]
104-
],
105-
'auth' => [$config->fields['username'], $config->fields['password']]
106-
]);
100+
try {
101+
$client->delete($config->fields['nextcloud_url'] . '/signature', [
102+
'json' => [
103+
'uuid' => $uuid,
104+
'users' => [
105+
['email' => $email]
106+
]
107+
],
108+
'auth' => [$config->fields['username'], $config->fields['password']]
109+
]);
110+
} catch (BadResponseException $e) {
111+
$return = $e->getResponse()->getBody()->getContents();
112+
$json = json_decode($return);
113+
if ($json && $json->message) {
114+
throw new Exception(__($json->message));
115+
}
116+
throw new Exception($return);
117+
}
107118
}
108119

109120
private static function getSignRequests($filter)

inc/httpclient.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
class PluginLibresignHttpclient extends Plugins
66
{
7-
public function request($method, $endpoint, $options)
7+
public function __call($method, $args)
88
{
9-
return $this->httpClient->request($method, $endpoint, $options);
9+
return call_user_func_array([$this->httpClient, $method], $args);
1010
}
1111
}

0 commit comments

Comments
 (0)