React is showing the regular developer errors even in the built and I want to handle at least some with errorboundray or similar, the actual customized errors are thrown by mongoose in my apollo client / express server / graphql implementation, apparently, componentDidCatch is not catching any. I have achieved to show some of them in order to be human-readable errors and a proper rendering but I can't cut the developer error behavior from React built, is it possible to implement a straight handler or add a className to the errors so they could be hidden in CSS?
Errors:
Uncaught (in promise) Error: GraphQL error:
ErrorBoundary:
import React, { Component } from "react";
export class ErrorBoundary extends Component {
constructor(props) {
super(props);
this.state = { error: null, errorInfo: null };
}
componentDidCatch(error, errorInfo) {
this.setState({
error: error,
errorInfo: errorInfo
});
}
render() {
if (this.state.errorInfo) {
return (
<div>
<h2>Something went wrong</h2>
<details style={{ whiteSpace: "pre-wrap" }}>
{this.state.error && this.state.error.toString()}
<br />
{this.state.errorInfo.componentStack}
</details>
</div>
);
}
// Render children if there's no error
return this.props.children;
}
}
export default ErrorBoundary;
Wrap:
import React from "react";
import Facebook from "./Facebook";
import Invoice from "./Invoice";
import ErrorBoundary from "./ErrorBoundary";
const Login = () => {
return (
<div>
<section className="header_text sub">
<img
className="pageBanner"
src="themes/images/pageBanner.png"
alt="New products"
/>
<h4>
<span>Sesión y Registro</span>
</h4>
</section>
<section className="main-content">
<div className="row">
<div className="span5">
<Facebook />
</div>
<ErrorBoundary>
<Invoice />
</ErrorBoundary>
</div>
</section>
</div>
);
};
export default Login;
Component:
import React, { useState } from "react";
import { useSelector } from "react-redux";
import { useMutation } from "@apollo/react-hooks";
import { useDispatch } from "react-redux";
import { addClientMutation, getClientQuery } from "../queries/queries";
import { addClientAction } from "../actions";
import ReCAPTCHA from "react-google-recaptcha";
const Invoice = props => {
let client = useSelector(state => state.login);
const dispatch = useDispatch();
const [newClient, setNewClient] = useState([]);
const [formDisable, setFormDisable] = useState(true);
const [addClientToDB, { error }] = useMutation(addClientMutation);
function refreshPage() {
window.location.reload(false);
}
if (error) {
console.log("error:", error);
...