Class: ResponseJSON

ResponseJSON


new ResponseJSON()

Response wrapper to structure the messages between our front and back

Version:
  • 1.0
Author:
  • Boris GBAHOUE
Source:

Methods


<static> exports.errorJSON()

Wrapper to build a ResponseJSON when an error occured
Every response generated as a result of a REST call is a JSON object.
In case of error, the data returned are more detailed and are useful
to understand why the request was rejected.

Source:
Returns:
  • JSON object
           - connection: ko
           - http_code: error code (set to 'http_code' param when not null or 500 otherwise)
           - message: a message explaining the problem in plain English
           - resource: the REST API called
           - method: the HTTP method used
           - data: other data to describe the issue

<static> exports.isValid(json)

Test if an Object is a proper ResponseJSON

Parameters:
Name Type Description
json Object
Source:
Returns:
Type
Boolean

<static> exports.processError(msg, req)

Process an error and returns a properly formatted JSON

Parameters:
Name Type Description
msg Object
req Express.Request
Source:
Returns:
Type
ErrorJSON

<static> exports.responseJSON()

Wrapper to build the ResponseJSON for non error replies
Every response generated as a result of a REST call is a JSON object.

Source:
Returns:
  • JSON object
           - If ok:
                   - connection: ok, ko
                   - http_code (as per http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
                           . 200 (ok): the request has succeeded
                           . 201 (created): the request has been fulfilled and resulted in a new resource being created
                           . 204 (no content): the server has fulfilled the request but does not need to return an entity-body
                   - data: object
           - If failed:
                   - message: a message explaining the problem in plain English
                   - resource: the REST API called
                   - method: the HTTP method used