Class: JSON_ADAPTER

JSON_ADAPTER

Baseline adapter class which handles wrapping response data in an object with a status code and result message. Formatting is configurable both for success and error responses

Constructor

new JSON_ADAPTER(optionsopt)

Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Configurable options for the adapter

Properties
Name Type Description
formatRender function

Overwrites default formatting behavior for json responses

formatError function

Overwrites default formatting behavior for errors

Source:

Methods

error(err, options, cbopt) → {*}

Creates a formatted error response

Parameters:
Name Type Attributes Default Description
err *

Any data to be sent as part of error response

options Object

Configurable options for error response formatting see _ERROR for more details

Properties
Name Type Attributes Description
sync Boolean

If ture execution of error will be handled synchronously

req Object <optional>

Express request object. If options.req and options.res are defined the express .render method will be used to render template

res Object <optional>

Express response object. If options.res and options.req are defined the express .render method will be used to render template

skip_response Boolean <optional>

If true function will resolve with the rendered template instead of sending a response

cb function <optional>
false

An optional callback function. If this argument is not a function it will be ignored

Source:
Returns:

Returns the formatted json object if options.sync is true or a Promise if cb arugement is not passed

Type
*

render(data, optionsopt, cbopt) → {*}

Creates a formatted response

Parameters:
Name Type Attributes Default Description
data *

Any data that should be sent with the success response

options Object <optional>
{}

Configurable options for success response formatting see _RENDER for more details

Properties
Name Type Attributes Description
req Object <optional>

Express request object. If options.req and options.res are defined the express .render method will be used to render template

res Object <optional>

Express response object. If options.res and options.req are defined the express .render method will be used to render template

skip_response Boolean <optional>

If true function will resolve with the rendered template instead of sending a response

sync Boolean

If true execution of render will be handled synchronously

cb function <optional>
false

An optional callback function. If this argument is not a function it will be ignored

Source:
Returns:

Returns the formatted json object if options.sync is true or a Promise if cb arugement is not passed

Type
*