@@ -182,18 +182,75 @@ Log Level only controls what needs to be logged.
182182| trace | TRACE |
183183
184184
185- # OpenST formatter usage
185+ # OpenST response formatter usage
186186
187187` ` ` bash
188+
189+ const rootPrefix = ' .'
190+ , paramErrorConfig = require(rootPrefix + ' /tests/mocha/lib/formatter/param_error_config' )
191+ , apiErrorConfig = require(rootPrefix + ' /tests/mocha/lib/formatter/api_error_config' )
192+ ;
193+
188194const OSTCore = require(' @openstfoundation/openst-base' )
189- , ResponseHelper = OSTCore.responseHelper;
195+ , ResponseHelper = OSTCore.responseHelper
196+ , responseHelper = new ResponseHelper({
197+ moduleName: ' companyRestFulApi'
198+ });
190199
191- responseHelper = new ResponseHelper ();
200+ //using error function
201+ responseHelper.error({
202+ internal_error_identifier: ' s_vt_1' ,
203+ api_error_identifier: ' test_1' ,
204+ debug_options: {client_id: 1234},
205+ error_config: {
206+ param_error_config: paramErrorConfig,
207+ api_error_config: apiErrorConfig
208+ }
209+ });
192210
193- //using successWithData function
194- responseHelper.successWithData({field: value});
211+ //using paramValidationError function
212+ responseHelper.paramValidationError({
213+ internal_error_identifier:" s_vt_2" ,
214+ api_error_identifier: " test_1" ,
215+ params_error_identifiers: [" user_name_inappropriate" ],
216+ debug_options: {client_id: 1234},
217+ error_config: {
218+ param_error_config: paramErrorConfig,
219+ api_error_config: apiErrorConfig
220+ }
221+ });
195222
196- //using error function
197- responseHelper.error(" err_code" , " Unhandled result" , {}, {sendErrorEmail: false});
223+ // Result object is returned from responseHelper method invocations above, we can chain several methods as shown below
224+
225+ responseHelper.error({
226+ internal_error_identifier: ' s_vt_1' ,
227+ api_error_identifier: ' invalid_api_params' ,
228+ debug_options: {client_id: 1234},
229+ error_config: {
230+ param_error_config: paramErrorConfig,
231+ api_error_config: apiErrorConfig
232+ }
233+ }).isSuccess ();
234+
235+ responseHelper.error({
236+ internal_error_identifier: ' s_vt_1' ,
237+ api_error_identifier: ' invalid_api_params' ,
238+ debug_options: {client_id: 1234},
239+ error_config: {
240+ param_error_config: paramErrorConfig,
241+ api_error_config: apiErrorConfig
242+ }
243+ }).isFailure ();
244+
245+ responseHelper.error({
246+ internal_error_identifier: ' s_vt_1' ,
247+ api_error_identifier: ' invalid_api_params' ,
248+ debug_options: {client_id: 1234},
249+ error_config: {
250+ param_error_config: paramErrorConfig,
251+ api_error_config: apiErrorConfig
252+ }
253+ }).toHash ();
254+
198255
199256` ` `
0 commit comments