0

enter image description here

Not really sure what's causing this error when I am typing in the wrong password. I keep getting this error even if I add an any type for the error

import React from 'react';
import { AxiosResponse } from 'axios';
import { Message } from 'semantic-ui-react';

interface IProps {
  error: AxiosResponse;
  text?: string;
}

const ErrorMessage: React.FC<IProps> = ({ error, text }) => {
  return (
    <Message error>
      <Message.Header>{error.statusText}</Message.Header>
      {error.data && Object.keys(error.data.errors).length > 0 && (
        <Message.List>
          {Object.values(error.data.errors).flat().map((err, i) => (
            <Message.Item key={i}>(err: any, i)</Message.Item>
          ))}
        </Message.List>
      )}
      {text && <Message.Content content={text} />}
    </Message>
  );
};

export default ErrorMessage;

1
  • Please include error messages as text, not as pictures of text. Commented Sep 14, 2020 at 17:46

1 Answer 1

1

You are getting this error because error.data.errors is undefined.

Try replacing

error.data && Object.keys(error.data.errors)

with

error.data && error.data.errors && Object.keys(error.data.errors)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much!!! This has been a problem for me for awhile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.