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

Handling errors in the Article Editor #32

@SudShekhar

Description

@SudShekhar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions