Skip to content
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

Add error parser / normaliser #19

Closed
sjurgis opened this issue Jun 2, 2018 · 2 comments
Closed

Add error parser / normaliser #19

sjurgis opened this issue Jun 2, 2018 · 2 comments

Comments

@sjurgis
Copy link

sjurgis commented Jun 2, 2018

The resulting error array is quite painful to parse, as a result I've wrote this spaghetti that recursively parses errors into a single array of messages.

It could probably be improved by adding errorType property.
It would be nice to just go enqueue(...).withErrorParser() and get simply iterable list of exceptions that you could just .join() and print to the screen.

getErrors : function(errors) {
   var messages = [];
   var helper = this;
   if(errors){
     var errata = Array.isArray(errors) ? errors : errors.entries;
     if(errata){
       errata.forEach(function(i){
        if(i.message) messages.push(i.message);
        if(i.pageErrors && i.pageErrors.length > 0) messages = [].concat(messages, helper.getErrors(i.pageErrors));
        if(i.fieldErrors) messages = [].concat(messages, helper.getErrors([].concat.apply([], Object.keys(i.fieldErrors).map(function(key) { return i.fieldErrors[key] }))));
       }) 
     }
   }
   return messages;
  }
@ruslan-kurchenko
Copy link
Owner

Hey @sjurgis!
Sounds good to me.
What about "plugin/feature" based approach? For example, create hooks in the component behavior where you can embed custom functionality as you mentioned?
Or, do you think it will be better to "hardcode/add" your function (decorator) directly to the component?

@ruslan-kurchenko
Copy link
Owner

Merged into #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants