Merge pull request #4780 from luisramos0/bulk_prod_errors

Fix javascript logic that parses server errors in the bulk product edit page
This commit is contained in:
Luis Ramos
2020-02-25 18:49:54 +00:00
committed by GitHub
4 changed files with 62 additions and 13 deletions

View File

@@ -0,0 +1,21 @@
# Parses a structure of errors that came from the server
angular.module("admin.utils").factory "ErrorsParser", ->
new class ErrorsParser
toString: (errors, defaultContent = "") =>
return defaultContent unless errors?
errorsString = ""
if errors.length > 0
# it is an array of errors
errorsString = errors.join("\n") + "\n"
else
# it is a hash of errors
keys = Object.keys(errors)
for key in keys
errorsString += errors[key].join("\n") + "\n"
this.defaultIfEmpty(errorsString, defaultContent)
defaultIfEmpty: (content, defaultContent) =>
return defaultContent if content == ""
content