Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit bd3a0c6

Browse files
DIOHz0rajsb85
authored andcommittedOct 29, 2017
feat(error): added error handler class
1 parent cdda13b commit bd3a0c6

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
 

‎src/Glpi/Api/Rest/ErrorHandler.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* --------------------------------------------------------------------
4+
*
5+
* LICENSE
6+
*
7+
* This file is part of the GLPI API Client Library for PHP,
8+
* a subproject of GLPI. GLPI is a free IT Asset Management.
9+
*
10+
* GLPI is free software: you can redistribute it and/or
11+
* modify it under the terms of the GNU General Public License
12+
* as published by the Free Software Foundation; either version 3
13+
* of the License, or (at your option) any later version.
14+
*
15+
* GLPI is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
* --------------------------------------------------------------------
20+
* @author Domingo Oropeza - <doropeza@teclib.com>
21+
* @copyright (C) 2017 Teclib' and contributors.
22+
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
23+
* @link https://github.com/glpi-project/php-library-glpi
24+
* @link http://www.glpi-project.org/
25+
* --------------------------------------------------------------------
26+
*/
27+
28+
namespace Glpi\Api\Rest;
29+
30+
class ErrorHandler {
31+
32+
const errors = [
33+
'ERROR_ITEM_NOT_FOUND' => "The desired resource (itemtype-id) was not found in the GLPI database.",
34+
'ERROR_BAD_ARRAY' => "The HTTP body must be an an array of objects.",
35+
'ERROR_METHOD_NOT_ALLOWED' => "You specified an inexistent or not not allowed resource.",
36+
'ERROR_RIGHT_MISSING' => "The current logged user miss rights in his profile to do the provided action. Alter this profile or choose a new one for the user in GLPI main interface.",
37+
'ERROR_SESSION_TOKEN_INVALID' => "The Session-Token provided in header is invalid. You should redo an Init session request.",
38+
'ERROR_SESSION_TOKEN_MISSING' => "You miss to provide Session-Token in header of your HTTP request.",
39+
'ERROR_APP_TOKEN_PARAMETERS_MISSING' => "The current API requires an App-Token header for using its methods.",
40+
'ERROR_NOT_DELETED' => "You must mark the item for deletion before actually deleting it",
41+
'ERROR_NOT_ALLOWED_IP' => "We can't find an active client defined in configuration for your IP. Go to the GLPI Configuration > Setup menu and API tab to check IP access.",
42+
'ERROR_LOGIN_PARAMETERS_MISSING' => "One of theses parameter(s) is missing: login and password or user_token",
43+
'ERROR_LOGIN_WITH_CREDENTIALS_DISABLED' => "The GLPI setup forbid the login with credentials, you must login with your user_token instead. See your personal preferences page or setup API access in GLPI main interface.",
44+
'ERROR_GLPI_LOGIN_USER_TOKEN' => "The provided user_token seems invalid. Check your personal preferences page in GLPI main interface.",
45+
'ERROR_GLPI_LOGIN' => "We cannot login you into GLPI. This error is not relative to API but GLPI core. Check the user administration and the GLPI logs files (in files/_logs directory).",
46+
'ERROR_ITEMTYPE_NOT_FOUND_NOR_COMMONDBTM' => "We cannot login you into GLPI. This error is not relative to API but GLPI core. Check the user administration and the GLPI logs files (in files/_logs directory).You asked a inexistent resource (endpoint). It's not a predefined (initSession, getFullSession, etc) nor a GLPI CommonDBTM resources. See this documentation for predefined ones or List itemtypes for available resources",
47+
'ERROR_SQL' => "We suspect an SQL error. This error is not relative to API but to GLPI core. Check the GLPI logs files (in files/_logs directory).",
48+
'ERROR_RANGE_EXCEED_TOTAL' => "The range parameter you provided is superior to the total count of available data.",
49+
'ERROR_GLPI_ADD' => "We cannot add the object to GLPI. This error is not relative to API but to GLPI core. Check the GLPI logs files (in files/_logs directory).",
50+
'ERROR_GLPI_PARTIAL_ADD' => "Some of the object you wanted to add triggers an error. Maybe a missing field or rights. You'll find with this error a collection of results.",
51+
'ERROR_GLPI_UPDATE' => "We cannot update the object to GLPI. This error is not relative to API but to GLPI core. Check the GLPI logs files (in files/_logs directory).",
52+
'ERROR_GLPI_PARTIAL_UPDATE' => "Some of the object you wanted to update triggers an error. Maybe a missing field or rights. You'll find with this error a collection of results.",
53+
'ERROR_GLPI_DELETE' => "We cannot delete the object to GLPI. This error is not relative to API but to GLPI core. Check the GLPI logs files (in files/_logs directory).",
54+
'ERROR_GLPI_PARTIAL_DELETE' => "Some of the objects you want to delete triggers an error, maybe a missing field or rights. You'll find with this error, a collection of results.",
55+
'ERROR_RESOURCE_NOT_FOUND_NOR_COMMONDBTM' => "Resource not found or not an instance of CommonDBTM",
56+
'ERROR_APILIB_ARGUMENTS' => "Missing o wrong argument(s) for this function, please check GLPI API and function documentation.",
57+
'ERROR_APILIB_ARGS_MANDATORY' => "Missing mandatory param(s) %s.",
58+
];
59+
60+
public static function getMessage($error, $args = null) {
61+
return printf(self::errors[$error], $args);
62+
}
63+
}

0 commit comments

Comments
 (0)