forked from michaelkirkpatrick/catalog-beer-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.php
97 lines (85 loc) · 3.59 KB
/
errors.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
// Initialize
include_once $_SERVER["DOCUMENT_ROOT"] . '/classes/initialize.php';
$json = array();
// Process Status Code
$code = $_GET['code'];
switch($code){
case 403:
// Show Error Message
$json['error'] = true;
$json['error_msg'] = "Forbidden - Sorry, you have requested a resource that you don't have permission to view. We've logged the error so our support team is aware of it. If you believe you shoudn't be seeing a 403 error for your request, please contact us: https://catalog.beer/contact";
// Log Error
$errorLog = new LogError();
$errorLog->errorNumber = 403;
$errorLog->errorMsg = '403 Error';
$errorLog->filename = 'API / errors.php';
$errorLog->write();
break;
case 404:
// Show Error Message
$json['error'] = true;
$json['error_msg'] = "Not Found - Sorry, we weren't able to find the resource you requested. That's a bummer. We've logged the error so our support team is aware of it. If you believe you shoudn't be seeing a 404 error for your request, please contact us: https://catalog.beer/contact";
// Log Error
$errorLog = new LogError();
$errorLog->errorNumber = 404;
$errorLog->errorMsg = '404 Error';
$errorLog->filename = 'API / errors.php';
$errorLog->write();
break;
case 405:
// Show Error Message
$json['error'] = true;
$json['error_msg'] = "Method Not Allowed - The requested method is not allowed for this URL. We've logged the error so our support team is aware of it. If you believe you shoudn't be seeing a 405 error for your request, please contact us: https://catalog.beer/contact";
// Log Error
$errorLog = new LogError();
$errorLog->errorNumber = 405;
$errorLog->errorMsg = '404 Error';
$errorLog->filename = 'API / errors.php';
$errorLog->write();
break;
case 500:
// Show Error Message
$json['error'] = true;
$json['error_msg'] = "Internal Server Error - Sorry, we seem to be having some difficulty serving you what you requested. That's a bummer; hopefully it will pass soon. We've logged the error so our support team is aware of it. If you believe you shoudn't be seeing a 500 error for your request, please contact us: https://catalog.beer/contact";
// Log Error
$errorLog = new LogError();
$errorLog->errorNumber = 500;
$errorLog->errorMsg = '500 Error';
$errorLog->filename = 'API / errors.php';
$errorLog->write();
break;
case 503:
// Show Error Message
$json['error'] = true;
$json['error_msg'] = "Service Unavailable - Sorry, the resource you requested is temporarily unavailable. That's a bummer; hopefully it will pass soon. We've logged the error so our support team is aware of it. If you believe you shoudn't be seeing a 503 error for your request, please contact us: https://catalog.beer/contact";
// Log Error
$errorLog = new LogError();
$errorLog->errorNumber = 503;
$errorLog->errorMsg = '503 Error';
$errorLog->filename = 'API / errors.php';
$errorLog->write();
break;
}
/* - - - - - RESPONSE - - - - - */
// HTTP Status Code
http_response_code($code);
// Header Type
header('Content-Type: application/json');
// Output JSON
if($json_encoded = json_encode($json)){
echo $json_encoded;
}else{
$json_orig = $json;
$json = array();
$json['error'] = true;
$json['error_msg'] = 'Sorry, we have encountered an encoding error and are unable to present your data at this time. We\'ve logged the issue and our support team will look into it.';
echo json_encode($json);
// Log Error
$errorLog = new LogError();
$errorLog->errorNumber = 134;
$errorLog->errorMsg = 'JSON Encoding Error';
$errorLog->badData = $json_orig;
$errorLog->filename = 'API / index.php';
$errorLog->write();
}