mirror of
https://github.com/friendica/friendica
synced 2024-12-27 04:00:16 +00:00
6b60560ea2
- Api functions can define an HTTP method to use to call them. "405 Method Not Allowed" is returned on error - Api function that modify data accepts only POST as method. - A list of HTTP return code related exception is added - Api functions throw HTTP exceptions instead of return false or die() - api_call() catches HTTP exceptions and return error message with corret HTTP response code - api_format_items() returns also item activities count (# of like/dislike etc) - api/friendica/photos/list return more info about photos. xml format added. - api/friendica/photo/detail return more info, links to all sizes, no data except if 'size' parameter is passed. xml format added. - new api api/friendica/activity/<verb> and api/friendica/activity/un<verb> to add or remove like/dislike/attend status
105 lines
2.1 KiB
PHP
105 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* Throwable exceptions to return HTTP status code
|
|
*
|
|
* This list of Exception has be extracted from
|
|
* here http://racksburg.com/choosing-an-http-status-code/
|
|
*/
|
|
|
|
class HTTPException extends Exception {
|
|
var $httpcode = 200;
|
|
var $httpdesc = "";
|
|
public function __construct($message="", $code = 0, Exception $previous = null) {
|
|
if ($this->httpdesc=="") {
|
|
$this->httpdesc = preg_replace("|([a-z])([A-Z])|",'$1 $2', str_replace("Exception","",get_class($this)));
|
|
}
|
|
parent::__construct($message, $code, $previous);
|
|
}
|
|
}
|
|
|
|
// 4xx
|
|
class TooManyRequestsException extends HTTPException {
|
|
var $httpcode = 429;
|
|
}
|
|
|
|
class UnauthorizedException extends HTTPException {
|
|
var $httpcode = 401;
|
|
}
|
|
|
|
class ForbiddenException extends HTTPException {
|
|
var $httpcode = 403;
|
|
}
|
|
|
|
class NotFoundException extends HTTPException {
|
|
var $httpcode = 404;
|
|
}
|
|
|
|
class GoneException extends HTTPException {
|
|
var $httpcode = 410;
|
|
}
|
|
|
|
class MethodNotAllowedException extends HTTPException {
|
|
var $httpcode = 405;
|
|
}
|
|
|
|
class NonAcceptableException extends HTTPException {
|
|
var $httpcode = 406;
|
|
}
|
|
|
|
class LenghtRequiredException extends HTTPException {
|
|
var $httpcode = 411;
|
|
}
|
|
|
|
class PreconditionFailedException extends HTTPException {
|
|
var $httpcode = 412;
|
|
}
|
|
|
|
class UnsupportedMediaTypeException extends HTTPException {
|
|
var $httpcode = 415;
|
|
}
|
|
|
|
class ExpetationFailesException extends HTTPException {
|
|
var $httpcode = 417;
|
|
}
|
|
|
|
class ConflictException extends HTTPException {
|
|
var $httpcode = 409;
|
|
}
|
|
|
|
class UnprocessableEntityException extends HTTPException {
|
|
var $httpcode = 422;
|
|
}
|
|
|
|
class ImATeapotException extends HTTPException {
|
|
var $httpcode = 418;
|
|
var $httpdesc = "I'm A Teapot";
|
|
}
|
|
|
|
class BadRequestException extends HTTPException {
|
|
var $httpcode = 400;
|
|
}
|
|
|
|
// 5xx
|
|
|
|
class ServiceUnavaiableException extends HTTPException {
|
|
var $httpcode = 503;
|
|
}
|
|
|
|
class BadGatewayException extends HTTPException {
|
|
var $httpcode = 502;
|
|
}
|
|
|
|
class GatewayTimeoutException extends HTTPException {
|
|
var $httpcode = 504;
|
|
}
|
|
|
|
class NotImplementedException extends HTTPException {
|
|
var $httpcode = 501;
|
|
}
|
|
|
|
class InternalServerErrorException extends HTTPException {
|
|
var $httpcode = 500;
|
|
}
|
|
|
|
|
|
|