Exceptions Raised by MN and CN APIs ----------------------------------- .. module:: Exceptions :synopsis: Exceptions that are raised by MN, CN, and ITK software. .. contents:: General ~~~~~~~ All exceptions raised by API methods in DataONE include three basic elements of information and an optional element ``traceInformation`` as detailed in :class:`Types.ErrorMessage`, repeated here for convenience. .. list-table:: :widths: 2 2 10 :header-rows: 1 * - Element - Cardinality - Description * - errorCode - 1 - The error code. This is the HTTP error code (i.e. 4xx). In all cases, the HTTP Status Code value in the response headers *should* match this value. * - detailcode - 1 - A code that can be mapped to a specific location in the source code of the implementation. Implemented as a string with dot notation to indicate progressive levels of detail. * - pid - 0..1 - Required for exceptions that include an identifier in the constructor signature (e.g. NotFound, IdentifierNotUnique, SynchronizationFailed). * - nodeId - 0..1 - The node identifier of the machine that raised the exception * - description - 0..1 - A human readable message describing what happened * - traceInformation - 0..1 - Optional free text providing more information about the error condition. The intent of this element is to assist with debugging. Note that care should be taken to ensure senstive information is not accidentally exposed through error conditions. Expressed in xml-schema: .. code-block:: xml .. _ExceptionCodes: HTTP Exception Handling Codes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HTTP error codes of relevance to the DataONE services are repeated here for convenience. Refer to the `HTTP specification`_ for a complete reference. .. list-table:: :widths: 1 2 5 :header-rows: 1 * - Code - Meaning - Description * - 400 - Bad Request - Bad request if the request REST operation is invalid, serialization is erroneous, mime type is not supported, or resource is not supported. * - 401 - Unauthorized - Authentication failure. Credentials are required or were invalid. * - 403 - Forbidden - The current user does not have the right to perform the requested action. * - 404 - Not Found - The requested resource does not exist. * - 405 - Method not allowed - The HTTP method used is not allowed on this resource. Response must include an Allow header indicating valid HTTP methods. * - 406 - Not Acceptable - The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request. * - 408 - Request Timeout - The client did not produce a request within the time that the server was prepared to wait. * - 409 - Conflict - The request could not be completed due to a conflict with the current state of the resource. * - 410 - Gone - The resource is known to be permanently deleted (as opposed to 404 which indicates uncertainty about the state of the object). * - 413 - Request Entity Too Large - The server is refusing to process a request because the request entity is larger than the server is willing or able to process. * - 415 - Unsupported Media Type - The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method. * - 500 - Internal Server Error - The server encountered an unexpected condition which prevented it from fulfilling the request. * - 501 - Not Implemented - The server does not support the functionality required to fulfill the request. This is the appropriate response when the server does not recognize the request method and is not capable of supporting it for any resource. .. _HTTP specification: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html Serializing Exceptions ~~~~~~~~~~~~~~~~~~~~~~ All error messages in DataONE are serialized in XML. In the future, DataONE interfaces may support additional serialization formats such as HTML and JSON, and the serialization format will be selected through normal HTTP content negotiation procedures (RFC2616_). An example of an XML serialized error message: .. code-block:: xml The specified object does not exist on this node. method: mn.get hint: http://cn.dataone.org/cn/resolve/123XYZ Note that the *detailCode*, *pid*, and *nodeId* attributes are optional. The *description* element is optional but strongly recommended, and *traceInformation* is optional though especially useful during development and testing. .. Exceptions can be serialized in different formats that vary according to where the error occurs and what caller the error message is being sent to. Four common serialization formats will be HTML, XML, JSON, and Log. The general approach for serializing error messages is indicated by way of example below. For errors raised in response to a HTTP call (e.g. through the REST interface), the error should be serialized in the format indicated in the request Accept header, defaulting to HTML. Examples of a :exc:`Exceptions.NotFound` error raised by a request to :func:`MNRead.get` object ``123XYZ`` from a Member Node. The trace information contains ``{'method':'mn.get'}``. In HTML: .. code-block:: html Error: 404 Not Found (1020.1)

Error
NotFound
Code
404
Detail Code
1020.1
Identifier
123XYZ
Node Identifier
c3p0

The specified object does not exist on this node.

            method: mn.get
            hint: Please try resolving http://cn.dataone.org/cn/resolve/123XYZ
          
In XML: In JSON:: { 'name': 'NotFound', 'errorCode':404, 'detailCode': '1020.1', 'pid': '123XYZ', 'nodeId': 'c3p0', 'description': 'The specified object does not exist on this node.', 'traceInformation': 'method: mn.get hint: http://cn.dataone.org/cn/resolve/123XYZ' } Log message body. This type of representation is presented here as a suggestion. The actual log representation may differ according to the actual implementation:: [detail:1020.1][pid:123XYZ, nodeId:c3p0, method:mn.get]The specified object does not exist on this node. .. _RFC2616: http://tools.ietf.org/html/rfc2616 The Exceptions ~~~~~~~~~~~~~~ .. include:: generated/generated_exception_summary.txt .. include:: generated/generated_exceptions.txt