Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using injection on UI #16

Open
vyadav61 opened this issue Jun 4, 2021 · 0 comments
Open

Error when using injection on UI #16

vyadav61 opened this issue Jun 4, 2021 · 0 comments

Comments

@vyadav61
Copy link

vyadav61 commented Jun 4, 2021

Hi there ,
Firstly thanks for creating this wonderful product and We are using your mountebank as a boilerplate for our use and we are getting some issue when retrying to inject the response from UI and hitting from postman.

Below is the json response which I am trying to inject .

function processRequest(request, state, logger) {
var handlebars = require('handlebars');
logger.info('hi');
// var JSON = require("JSON3")
// var sentIn = JSON.stringify(request, null);
//logger.info('sentIn ' + sentIn);
var source = '{"Success": {{title}},"ProcessingTimeMilliseconds" : 139, "ResponseMessage": "","CreateLetter":{"OrderItemId":{{random}}}, "CancelLetter":null,"CheckLetterStatus":{{random}},"ReprintLetter":null , "ResendLetter":null}';
var ran = Math.ceil(Math.random() * 1000000);
var data = {
"title": true,
"random": ran
};

var template = handlebars.compile(source);
var textJSON = template(data);
return {
headers: {
'Content-Type': 'application/json'
},
body: textJSON,
statusCode: 200
};
After hitting from postman I am getting the below error, can you please help me with that.

{
"errors": [
{
"code": "invalid injection",
"message": "invalid response injection",
"source": "(function processRequest(request, state, logger) {\n var handlebars = require('handlebars');\n logger.info('hi');\n // var JSON = require("JSON3")\n // var sentIn = JSON.stringify(request, null);\n //logger.info('sentIn ' + sentIn);\n var source = '{"Success": {{title}},"ProcessingTimeMilliseconds" : 139, "ResponseMessage": "","CreateLetter":{"OrderItemId":{{random}}}, "CancelLetter":null,"CheckLetterStatus":{{random}},"ReprintLetter":null , "ResendLetter":null}';\n var ran = Math.ceil(Math.random() * 1000000);\n\n var data = {\n "title": true,\n "random": ran\n };\n\n var template = handlebars.compile(source);\n var textJSON = template(data);\n return {\n headers: {\n 'Content-Type': 'application/json'\n },\n body: textJSON,\n statusCode: 200\n };\n})(config, injectState, logger, deferred.resolve, imposterState);",
"data": "Parse error on line 1:\n...rderItemId":{{random}}}, "CancelLetter":\n-----------------------^\nExpecting 'CLOSE', 'OPEN_SEXPR', 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'CLOSE_UNESCAPED'",
"name": "Error",
"stack": "Error\n at Object.from (/core/src/util/inherit.js:15:17)\n at createError (/core/src/util/errors.js:10:26)\n at Object.InjectionError (/core/src/util/errors.js:21:34)\n at inject (/core/src/models/responseResolver.js:57:44)\n at processResponse (/core/src/models/responseResolver.js:297:20)\n at Object.resolve (/core/src/models/responseResolver.js:332:16)\n at match.stub.nextResponse.then.responseConfig (/core/src/models/imposter.js:130:33)\n at _fulfilled (/core/node_modules/q/q.js:854:54)\n at self.promiseDispatch.done (/core/node_modules/q/q.js:883:30)\n at Promise.promise.promiseDispatch (/core/node_modules/q/q.js:816:13)"
}
]
}

It would be a great help if you can send me the resolution for the above error.

Thanks,
Vishnu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant