Class: TAbstractResponder

Databases/TAbstractResponder~ TAbstractResponder

The TAbstractResponder is the base class for all derived database controller that require to send a response to client. It allow to send preformatted response in function of database query result.

new TAbstractResponder()

Source:

Methods


<private, static> _formatError(error)

Normalize error that can be in different format like single string, object, array of string, or array of object.
Parameters:
Name Type Description
error String | Object | Error The error object to normalize
Source:
Returns:
Type
AbstractHTTPError
Example

Normalized error are simple literal object like:

{
    name: 'TypeError',
    message: 'the error message'
}

<private, static> _formatErrors(error)

Normalize errors that can be in different format like single string, object, array of string, or array of object.
Parameters:
Name Type Description
error String | Object | Array.<String> | Array.<Object> The error object to normalize
Source:
Returns:
Type
Array.<Object>
Example

Normalized error are simple literal object like:

{
    name: 'TypeError',
    message: 'the error message'
}

<static> returnData(data, response)

In case database call return some data. If response parameter is a function consider this is a returnData callback function to call, else check if server response headers aren't send yet, and return response with status 200 and stringified data as content
Parameters:
Name Type Description
data The server/database data
response The server response or returnData callback
Source:
Returns:
callback call or response with status 200 and associated data
Type
*

<static> returnError(error, response)

In case database call return an error. If response parameter is a function consider this is a returnError callback function to call, else check if server response headers aren't send yet, log and flush stack trace (if allowed) and return response with status 500 and stringified error as content
Parameters:
Name Type Description
error A server/database error
response The server response or returnError callback
Source:
Returns:
callback call or response with status 500 and associated error
Type
*

<static> returnErrorAndData(error, data, response)

In case database call return some data AND error. If response parameter is a function consider this is a returnErrorAndData callback function to call, else check if server response headers aren't send yet, log and flush stack trace (if allowed) and return response with status 406 with stringified data and error in a literal object as content
Parameters:
Name Type Description
error A server/database error
data The server/database data
response The server response or returnErrorAndData callback
Source:
Returns:
callback call or response with status 406, associated error and data
Type
*

<static> returnNotFound(response)

In case database call return nothing consider that is a not found. If response parameter is a function consider this is a returnNotFound callback function to call, else check if server response headers aren't send yet, and return response with status 204
Parameters:
Name Type Description
response The server response or returnNotFound callback
Source:
Returns:
callback call or response with status 204
Type
*