Skip to content

Commit 5fa812a

Browse files
mikegsmith76kazsaj
authored andcommitted
JAPI Maintenance Exception (#11)
* Listen for maintenance exceptions and return the appropriate response code * Update message
1 parent 8a022b3 commit 5fa812a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/Docnet/JAPI.php

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use \Docnet\JAPI\Exceptions\Routing as RoutingException;
2020
use \Docnet\JAPI\Exceptions\Auth as AuthException;
21+
use \Docnet\JAPI\Exceptions\Maintenance as MaintenanceException;
2122

2223
/**
2324
* Front controller for our JSON APIs
@@ -74,10 +75,16 @@ public function run()
7475
$obj_router = $this->getRouter();
7576
$obj_router->route();
7677
$obj_router->dispatch();
78+
79+
} catch (MaintenanceException $obj_ex) {
80+
$this->jsonError('Service Temporarily Unavailable', 503);
81+
7782
} catch (RoutingException $obj_ex) {
7883
$this->jsonError($obj_ex, 404);
84+
7985
} catch (AuthException $obj_ex) {
8086
$this->jsonError($obj_ex, 401);
87+
8188
} catch (\Exception $obj_ex) {
8289
$this->jsonError($obj_ex);
8390
}
@@ -114,6 +121,9 @@ protected function jsonError($mix_message = NULL, $int_code = 500)
114121
case 404:
115122
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found", TRUE, 404);
116123
break;
124+
case 503:
125+
header($_SERVER["SERVER_PROTOCOL"] . " 503 Service Unavailable", TRUE, 503);
126+
break;
117127
case 500:
118128
default:
119129
header($_SERVER["SERVER_PROTOCOL"] . " 500 Internal Server Error", TRUE, 500);
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright 2014 Docnet
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
namespace Docnet\JAPI\Exceptions;
18+
19+
/**
20+
* Class Maintenance
21+
*
22+
* @author Mike Smith <[email protected]>
23+
* @package Docnet\JAPI\Exceptions
24+
*/
25+
class Maintenance extends \Exception
26+
{
27+
}

0 commit comments

Comments
 (0)