Skip to content

Commit

Permalink
Merge pull request #2320 from dcos/orlandohohmeier/1.9/fix/DCOS-17242…
Browse files Browse the repository at this point in the history
…-adjust-marathon-errors-parse-util

↩️  DCOS-17242: Adjust MarathonErrorUtil to handle missing detail errors
  • Loading branch information
Orlando Hohmeier authored Jul 17, 2017
2 parents a7f6ea4 + f3fd0ae commit d0e040e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plugins/services/src/js/utils/MarathonErrorUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const MarathonErrorUtil = {
}

// `details` can be an array of errors
return error.details.reduce(function(memo, { errors, path }) {
return error.details.reduce(function(memo, { errors = [], path }) {
// Convert marathon path components to a dot-separated string
// and then split it into an array
//
Expand All @@ -121,6 +121,10 @@ const MarathonErrorUtil = {
});
}

if (errors.length === 0) {
errors = errors.concat(error.message);
}

// For every error, create the correct message
return errors.reduce(function(memo, errorMessage) {
memo.push({
Expand Down
41 changes: 41 additions & 0 deletions plugins/services/src/js/utils/__tests__/MarathonErrorUtil-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,47 @@ describe("MarathonErrorUtil", function() {
]);
});

it("translates messages with no detail errors", function() {
const marathonError = {
message: "Some error",
details: [
{
path: "/some/property"
}
]
};

expect(MarathonErrorUtil.parseErrors(marathonError)).toEqual([
{
path: ["some", "property"],
message: "Some error",
type: ServiceErrorTypes.GENERIC,
variables: {}
}
]);
});

it("translates messages with empty detail errors", function() {
const marathonError = {
message: "Some error",
details: [
{
errors: [],
path: "/some/property"
}
]
};

expect(MarathonErrorUtil.parseErrors(marathonError)).toEqual([
{
path: ["some", "property"],
message: "Some error",
type: ServiceErrorTypes.GENERIC,
variables: {}
}
]);
});

it("should properly translate marathon paths with index", function() {
const marathonError = {
message: "Some error",
Expand Down

0 comments on commit d0e040e

Please sign in to comment.