-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Exceptions.php
81 lines (68 loc) · 2.56 KB
/
Exceptions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
declare(strict_types=1);
namespace OCA\Memories;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
class Exceptions
{
public static function Generic(\Exception $e, int $status = Http::STATUS_INTERNAL_SERVER_ERROR): HttpResponseException
{
return new HttpResponseException(new DataResponse([
'message' => $e->getMessage(),
], $status));
}
public static function NotLoggedIn(): HttpResponseException
{
return new HttpResponseException(new DataResponse([
'message' => 'User not logged in',
], Http::STATUS_PRECONDITION_FAILED));
}
public static function NotEnabled(string $app): HttpResponseException
{
return new HttpResponseException(new DataResponse([
'message' => "{$app} app not enabled or not the required version.",
], Http::STATUS_PRECONDITION_FAILED));
}
public static function NoRequestRoot(): HttpResponseException
{
return new HttpResponseException(new DataResponse([
'message' => 'Request root could not be determined',
], Http::STATUS_NOT_FOUND));
}
public static function NotFound(string $ctx): HttpResponseException
{
return new HttpResponseException(new DataResponse([
'message' => "Not found ({$ctx})",
], Http::STATUS_NOT_FOUND));
}
public static function NotFoundFile(null|int|string $identifier): HttpResponseException
{
return new HttpResponseException(new DataResponse([
'message' => "File not found ({$identifier})",
], Http::STATUS_NOT_FOUND));
}
public static function Forbidden(string $ctx): HttpResponseException
{
return new HttpResponseException(new DataResponse([
'message' => "Forbidden ({$ctx})",
], Http::STATUS_FORBIDDEN));
}
public static function ForbiddenFileUpdate(string $name): HttpResponseException
{
return new HttpResponseException(new DataResponse([
'message' => "Forbidden ({$name} cannot be updated)",
], Http::STATUS_FORBIDDEN));
}
public static function MissingParameter(string $name): HttpResponseException
{
return new HttpResponseException(new DataResponse([
'message' => "Missing parameter ({$name})",
], Http::STATUS_BAD_REQUEST));
}
public static function BadRequest(string $ctx): HttpResponseException
{
return new HttpResponseException(new DataResponse([
'message' => "Bad Request ({$ctx})",
], Http::STATUS_BAD_REQUEST));
}
}