Beispiel #1
0
 private function error_message($resource, $method, $resource_type = 'resource')
 {
     /*
        Error message for each type of resource
     */
     $error = null;
     $error_info = null;
     $error_response = array("message" => null, "code" => null);
     if ($resource instanceof STDClass) {
         if (property_exists($resource, "error")) {
             $error_info = $resource->error;
         } elseif (property_exists($resource, "code") && property_exists($resource, "status")) {
             $error_info = $resource;
         }
     }
     if ($error_info != null && property_exists($error_info, "code")) {
         $code = $error_info->code;
         $error_response["code"] = $code;
         if (property_exists($error_info, "status") && property_exists($error_info->status, "message")) {
             $error = $error_info->status->message;
             $extra = null;
             if (property_exists($error_info->status, "extra")) {
                 $extra = $error_info->status->extra;
             }
             if ($extra != null) {
                 if ($extra instanceof STDClass) {
                     $error = $error . ":";
                     $error_response["code"] = $extra->error;
                     foreach (get_object_vars($extra) as $key => $value) {
                         $error = $error . $key . ": " . json_encode($value) . " ";
                     }
                     $error = $error . "\n";
                 } else {
                     $error = $error . ": " . $extra[0];
                 }
             }
         }
         if ($code == BigMLRequest::HTTP_NOT_FOUND && strtolower($method) == 'get') {
             $alternate_message = '';
             if (BigML::getDomain() != null && BigML::getDomain() != BigML::BIGML_ENDPOINT) {
                 $alternate_message = "The " . $resource_type . " was not created in " . BigML::getDomain() . "\n";
             }
             $error = $error . "\nCouldn\\'t find a " . $resource_type . " matching the given id. The most probable causes are:\n\n" . $alternate_message . " A typo in the " . $resource_type . "'s id.\n The " . $resource_type . " id cannot be accessed with your credentials.\n \nDouble-check your " . $resource_type . " and credentials info and retry.";
         } elseif ($code == BigMLRequest::HTTP_UNAUTHORIZED) {
             $error = $error . '\\nDouble-check your credentials, please.';
         } elseif ($code == BigMLRequest::HTTP_BAD_REQUEST) {
             $error = $error . '\\nDouble-check the arguments for the call, please.';
         } elseif ($code == BigMLRequest::HTTP_TOO_MANY_REQUESTS) {
             $error = $error . '\\nToo many requests. Please stop requests for a while before resuming.';
         } elseif ($code == BigMLRequest::HTTP_PAYMENT_REQUIRED) {
             $error = $error . '\\nYou\'ll need to buy some more credits to perform the chosen action';
         }
         $error_response["message"] = $error;
         return $error_response;
     }
     $error_response["message"] = "Invalid" . $resource_type . "structure:\n\n" . $resource;
     return $error_response;
 }