Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions openml_OS/controllers/Api_new.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,23 @@ private function bootstrap($version) {

// TODO: very important (for future versions of the API)!
if ($this->database_connection_error) {
$this->Api_data->returnError(107, $this->version);
$this->Api_data->returnError(107, $this->version, 412, null, false, false, $outputFormat);
return;
}

$request_type = strtolower($_SERVER['REQUEST_METHOD']);
if ($this->authenticated == false && $request_type != 'get') {
if ($this->provided_hash) {
$this->Api_data->returnError(103, $this->version);
$this->Api_data->returnError(103, $this->version, 412, null, false, false, $outputFormat);
} else {
$this->Api_data->returnError(102, $this->version);
$this->Api_data->returnError(102, $this->version, 412, null, false, false, $outputFormat);
}
} else if ($this->authenticated == false && $this->provided_hash) {
$this->Api_data->returnError(103, $this->version);
$this->Api_data->returnError(103, $this->version, 412, null, false, false, $outputFormat);
} else if ($this->user_has_writing_rights == false && $request_type != 'get') {
$this->Api_data->returnError(104, $this->version, $this->openmlGeneralErrorCode, 'API calls of the read-only user can only be of type GET. ');
$this->Api_data->returnError(104, $this->version, $this->openmlGeneralErrorCode, 'API calls of the read-only user can only be of type GET. ', false, false, $outputFormat);
} else if (file_exists(APPPATH.'models/api/' . $this->version . '/Api_' . $type . '.php') == false && $type != 'xsd' && $type != 'xml_example' && $type != 'arff_example') {
$this->Api_data->returnError(100, $this->version);
$this->Api_data->returnError(100, $this->version, 412, null, false, false, $outputFormat);
} else if($type == 'xsd') {
$this->server_document('xsd', $segs[0] . '.xsd', 'v1', 'Content-type: text/xml; charset=utf-8');
} else if($type == 'xml_example') {
Expand Down
9 changes: 8 additions & 1 deletion openml_OS/core/MY_Api_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,21 @@ function xmlToArray($xml, $options = array()) {
);
}

public function returnError($code, $version, $httpErrorCode = 412, $additionalInfo = null, $emailLog = false, $supress_output = false) {
public function returnError($code, $version, $httpErrorCode = 412, $additionalInfo = null, $emailLog = false, $supress_output = false, $outputFormat = null) {
$this->Log->api_error('error', $_SERVER['REMOTE_ADDR'], $code, $_SERVER['QUERY_STRING'], $this->load->apiErrors[$code] . (($additionalInfo == null)?'':$additionalInfo) );
$error['code'] = $code;
$error['message'] = htmlentities( $this->load->apiErrors[$code] );
$error['additional'] = htmlentities( $additionalInfo );
if (!$supress_output) {
http_response_code($httpErrorCode);
$originalFormat = $this->outputFormat;
if ($outputFormat !== null) {
$this->outputFormat = $outputFormat;
}
$this->xmlContents('error-message', $version, $error);
if ($outputFormat !== null) {
$this->outputFormat = $originalFormat;
}
}
if ($emailLog && defined('EMAIL_API_LOG')) {
$to = EMAIL_API_LOG;
Expand Down
12 changes: 12 additions & 0 deletions openml_OS/views/pages/api_new/v1/json/error-message.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
$error_response = array(
'error' => array(
'code' => $code,
'message' => $message
)
);
if ($additional != null) {
$error_response['error']['additional_information'] = $additional;
}
echo json_encode($error_response);
?>