Main Content

Troubleshooting RESTful API Errors

Since communication between the client and MATLAB® Production Server™ is over HTTP, many errors are indicated by an HTTP status code. Errors in the deployed MATLAB function use a different format. For more information, see Structure of MATLAB Error. To review RESTful API usage, see RESTful API for MATLAB Function Execution.

Structure of HTTP Error

{ 
    "error": { 
        "type": "httperror", 
        "code": 404, 
        "messageId": "ComponentNotFound", 
        "message": "Component not found." 
    } 
}

HTTP Status Codes

400–Bad Request

MessageDescription
Invalid inputClient request is not formatted correctly.
Invalid JSONClient request does not contain a valid JSON representation.
nargout missingClient request does not specify nargout containing output arguments.
rhs missingClient request does not specify rhs containing input arguments.
Invalid rhsInput arguments do not follow the JSON representation for MATLAB data types. For more information, see JSON Representation of MATLAB Data Types.

403–Forbidden

MessageDescription
The client is not authorized to access the requested componentClient does not have the correct credentials to make a request.

404–Not Found

MessageDescription
Function not foundServer is unable to find the MATLAB function in the deployed CTF archive
Component not foundServer is unable to find the CTF archive
URI-path not of form '/APPLICATION/FUNCTION'URL is not in the correct format

405–Method Not Allowed

MessageDescription
Bad MethodMethod is not allowed
Method must be POSTMethod is not allowed
Unsupported methodMethod is not allowed

411–Length Required

MessageDescription
Content-length missingLength of the content is missing

415–Unsupported Media Type

MessageDescription
<VALUE> is not an accepted content typeContent type for JSON is incorrect.

500–Internal Server Error

MessageDescription
Function return type not supportedMATLAB function deployed on the server returned a MATLAB data type that MATLAB Production Server does not support. For information about the data types that the MATLAB Production Server supports, see JSON Representation of MATLAB Data Types.

Resource Query vs Resource States

Resources / Server States

NOT_FOUND

READING

IN_QUEUE

PROCESSING

READY

ERROR

CANCELLED

DELETED / PURGED

UNKNOWN SERVER ERROR

GET $request-uri/result

404 - RequestNotFound

204 - NoContent

204 - NoContent

204 - NoContent

200 - OK

200 - OK

410 - RequestAlreadyCancelled

410 - RequestAlreadyDeleted

500 - InternalServerError

POST $request-uri/cancel

404 - RequestNotFound

204 - NoContent

204 - NoContent

204 - NoContent

410 - RequestAlreadyCompleted

410 - RequestAlreadyCompleted

410 - RequestAlreadyCancelled

410 - RequestAlreadyDeleted

500 - InternalServerError

DELETE $request-uri

404 - RequestNotFound

409 - RequestNotCompleted

409 - RequestNotCompleted

409 - RequestNotCompleted

204 - NoContent

204 - NoContent

204 - NoContent

410 - RequestAlreadyDeleted

500 - InternalServerError

Structure of MATLAB Error

To resolve a MATLAB error, troubleshoot the MATLAB function deployed on the server.

{
  "error": {
  "type": "matlaberror",
    "id": error_id,
    "message": error_message,
    "stack": [
      {
        "file": file_name1, 
        "name": function_name1, 
        "line": file_line_number1
      },
      {
        "file": file_name2, 
        "name": function_name2, 
        "line": file_line_number2
       },
       ...
    ]
  }
}

Access-Control-Allow-Origin

Client programmers using JavaScript® need to verify whether Cross-Origin Resource Sharing (CORS) is enabled on a MATLAB Production Server instance, if their clients programs make requests from different domains. If CORS is not enabled, you may get the following error message:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

For information on how to enable CORS, see cors-allowed-origins.

Related Topics