-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
httpError does not work when created from the Javascript API #527
Comments
I've created the simplest Node project that can reproduce this issue here: https://github.com/hq-mobile/mockserver-httperror |
Interestingly when updating to the latest MockServer (5.4.1) the error is a little more helpful:
Suggesting the Node client may be sending the expectation incorrectly? |
Yep, the request body sent by the node client automatically adds on a httpResponse object:
|
Ok I have narrowed this down to the fact that a default httpResponse with some headers is added regardless of whether httpError and other valid objects are specified when the request is being mocked using mockAnyResponse: var mockAnyResponse = function (expectation) {
return makeRequest(host, port, "/expectation", addDefaultExpectationHeaders(expectation));
};
var addDefaultExpectationHeaders = function (expectation) {
if (Array.isArray(expectation)) {
for (var i = 0; i < expectation.length; i++) {
expectation[i].httpRequest = addDefaultRequestMatcherHeaders(expectation[i].httpRequest);
expectation[i].httpResponse = addDefaultResponseMatcherHeaders(expectation[i].httpResponse);
}
} else {
expectation.httpRequest = addDefaultRequestMatcherHeaders(expectation.httpRequest);
expectation.httpResponse = addDefaultResponseMatcherHeaders(expectation.httpResponse);
}
return expectation;
}; It feels like there should be some conditional logic in the implementation to var addDefaultExpectationHeaders = function (expectation) {
if (Array.isArray(expectation)) {
for (var i = 0; i < expectation.length; i++) {
expectation[i].httpRequest = addDefaultRequestMatcherHeaders(expectation[i].httpRequest);
expectation[i].httpResponse = addDefaultResponseMatcherHeaders(expectation[i].httpResponse);
}
} else {
expectation.httpRequest = addDefaultRequestMatcherHeaders(expectation.httpRequest);
// PATCH STARTS HERE
if (!expectation.httpError) { // And others
expectation.httpResponse = addDefaultResponseMatcherHeaders(expectation.httpResponse);
}
// PATCH ENDS HERE
}
return expectation;
}; Patching the Node SDK with the implementation of
|
This has now been fixed and will be in the next release of mockserver-client-node |
When attempting to create an error expectation using the Javascript client e.g.
MockServer throws an error with the text:
The text was updated successfully, but these errors were encountered: