Handle the case when errors is a string

This commit is contained in:
Jean-Baptiste Bellet
2022-07-05 15:48:31 +02:00
parent d71994189c
commit b2a0310e6f
2 changed files with 7 additions and 3 deletions

View File

@@ -5,15 +5,16 @@ angular.module("admin.utils").factory "ErrorsParser", ->
return defaultContent unless errors?
errorsString = ""
if errors.length > 0
if Array.isArray(errors)
# it is an array of errors
errorsString = errors.join("\n") + "\n"
else
else if typeof errors == "object"
# it is a hash of errors
keys = Object.keys(errors)
for key in keys
errorsString += errors[key].join("\n") + "\n"
else # string
errorsString = errors
this.defaultIfEmpty(errorsString, defaultContent)
defaultIfEmpty: (content, defaultContent) =>