Categories: php, mysql, reactjs, redux, slim

Logging application errors to Database table [closed]

1 answer

Im trying to find the best way to save errors to a database table for better error tracking. My app has a React/Redux front end with the backend built in PHP Slim. We are running a MYSQL database.

I am just trying to get a feel of where would be the best place to do this.

Has anyone done this in the past or have an idea? I was thinking of doing a middleware in slim and catching errors there but I am new to slim therefore, I am not 100% sure how to acccomplish this the best way. The documentation really didnt provide much help on this.

Received answer to this question:
The best answer according to the author of the question:

You can use the componentDidCatch lifecycle to catch an error and then send an HTTP request to a server with axios like this:

I think it is best to use it in your main component which is usually App.js so that it catches any errors that might occur in the entire application.

import axios from 'axios';  class App extends React.Component {     componentDidCatch(error, info) {'/app-error', { error:error, info:info } );     } } 

To learn more about Error Boundaries check the docs: