Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Handling errors in the Article Editor #32

Open
SudShekhar opened this issue Jan 15, 2017 · 0 comments
Open

Handling errors in the Article Editor #32

SudShekhar opened this issue Jan 15, 2017 · 0 comments

Comments

@SudShekhar
Copy link

First of all, thanks for this making this. It clarified a lot of react/redux concepts for me.

I opened this PR to point out that

  • /editor page can be accessed without logging in
  • Clicking submit on this page without logging in causes the app to throw an error
  • Even if you're logged in and you click submit without filling out all the form fields, the app throws an error

Main reasons, in reducers/common.js

case 'ARTICLE_SUBMITTED':
      const redirectUrl = `article/${action.payload.article.slug}`;
      return { ...state, redirectTo: redirectUrl };

When ARTICLE_SUBMITTED doesn't succeed, there is no article returned and an error is thrown. This might work better

case 'ARTICLE_SUBMITTED':
        if(!action.error){
          const redirectUrl = `article/${action.payload.article.slug}`;
          return { ...state, redirectTo: redirectUrl };
        }
        break;

In reducers/editor.js, when you're not logged in the server returns a 401 and an error occurs below (Since the payload is empty):

case 'ARTICLE_SUBMITTED':
      return {
        ...state,
        inProgress: null,
        errors: action.error ? action.payload.errors : null
      };

Changing the above to this works:

case 'ARTICLE_SUBMITTED':
         return {
            ...state,
            inProgress: null,
            errors: action.error? 
               (action.payload? action.payload.errors: ["Unauthorized"]) : null
         };

I've hardcoded "Unauthorized" here but I guess there might be much better approaches for this.
Just my two cents. Thanks for the amazing tutorial.

@SudShekhar SudShekhar changed the title Handling unauthorized access/form errors in Editor.js Handling errors in the new post Editor Jan 15, 2017
@SudShekhar SudShekhar changed the title Handling errors in the new post Editor Handling errors in the Article Editor Jan 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant