Skip to content

Commit

Permalink
Merge pull request #755 from mesosphere/fix/3763-general-errors
Browse files Browse the repository at this point in the history
Fix - 3763 Enable multiple general errors from server response
  • Loading branch information
Poltergeist committed Apr 14, 2016
2 parents 9bea58b + 646ad2d commit 3f8c366
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## Unversioned
### Fixed
- \#3763 - Enable multiple general errors from server response

## 1.1.1 - 2016-04-13
### Added
- \#3658 - Allow Kill & Wipe for resident tasks
Expand Down
11 changes: 9 additions & 2 deletions src/js/components/modals/AppModalComponent.jsx
Expand Up @@ -141,12 +141,19 @@ var AppModalComponent = React.createClass({

if (Util.isObject(error)) {
error = Object.keys(error).map(key => {
return `${key}: ${error[key]}`;
var errorMsg = error[key];
if (Util.isArray(errorMsg)) {
return errorMsg.map(message => {
return `${key}: ${message}`;
});
}
return `${key}: ${errorMsg}`;
});
}

if (Util.isArray(error)) {
error = error.map((message, index) =>
var flattenedErrors = [].concat.apply([], error);
error = flattenedErrors.map((message, index) =>
<li key={index}><AutolinkComponent text={message} /></li>
);
} else {
Expand Down
11 changes: 10 additions & 1 deletion src/js/stores/AppFormStore.js
Expand Up @@ -395,6 +395,9 @@ function processResponseErrors(responseErrors, response, statusCode) {

} else if (statusCode === 422 && response != null &&
Util.isArray(response.details)) {

responseErrors.general = [];

response.details.forEach(detail => {
var attributePath = "general";

Expand All @@ -419,8 +422,14 @@ function processResponseErrors(responseErrors, response, statusCode) {
error = response.message;
}

responseErrors[fieldId] =
let serverResponseMessage =
AppFormErrorMessages.lookupServerResponseMessage(error);

if (fieldId === "general") {
responseErrors.general.push(serverResponseMessage);
} else {
responseErrors[fieldId] = serverResponseMessage;
}
});

} else if (statusCode === 409 && responseHasDeployments) {
Expand Down
38 changes: 35 additions & 3 deletions src/test/scenarios/createApplication.test.js
Expand Up @@ -204,7 +204,7 @@ describe("Create Application", function () {

AppsStore.once(AppsEvents.CREATE_APP_ERROR, function () {
expectAsync(function () {
expect(AppFormStore.responseErrors.general)
expect(AppFormStore.responseErrors.general[0])
.to.equal("Groups and Applications may not have the same " +
"identifier: /sleep");
}, done);
Expand All @@ -226,12 +226,44 @@ describe("Create Application", function () {
});
});

it("processes a 422 multiple error response correctly",
function (done) {

nock(config.apiURL)
.post("/v2/apps")
.reply(422, {
"message": "Object is not valid",
"details": [{
"path": "/",
"errors": ["Groups and Applications may not have the same " +
"identifier: /sleep"]
}, {
"path": "/",
"errors": ["This is a second unmapped error"]
}]
});

AppsStore.once(AppsEvents.CREATE_APP_ERROR, function () {
expectAsync(function () {
expect(AppFormStore.responseErrors.general)
.to.deep.equal(["Groups and Applications may not have the same " +
"identifier: /sleep",
"This is a second unmapped error"
]);
}, done);
});

AppsActions.createApp({
id: "sleep/my-app"
});
});

it("processes a 422 error response with no error details correctly",
function (done) {

AppsStore.once(AppsEvents.CREATE_APP_ERROR, function () {
expectAsync(function () {
expect(AppFormStore.responseErrors.general)
expect(AppFormStore.responseErrors.general[0])
.to.equal("Object is not valid");
}, done);
});
Expand All @@ -255,7 +287,7 @@ describe("Create Application", function () {

AppsStore.once(AppsEvents.CREATE_APP_ERROR, function () {
expectAsync(function () {
expect(AppFormStore.responseErrors.general)
expect(AppFormStore.responseErrors.general[0])
.to.equal("May not be changed.");
}, done);
});
Expand Down

0 comments on commit 3f8c366

Please sign in to comment.