domains / / axios/axios
Complete error handling chain
Implement comprehensive error handling throughout the codebase by ensuring all error scenarios are properly caught, typed, and propagated. This includes always including catch blocks for async operations, properly typing and propagating error information, using standardized error codes, and ensuring error callbacks receive and handle error parameters.
Implement comprehensive error handling throughout the codebase by ensuring all error scenarios are properly caught, typed, and propagated. This includes:
- Always include catch blocks for async operations
- Properly type and propagate error information
- Use standardized error codes for consistent error handling
- Ensure error callbacks receive and handle error parameters
Example:
// Bad
import(modulePath)
.then(module => {
module.default(req, res);
});
// Good
import(modulePath)
.then(module => {
module.default(req, res);
})
.catch(error => {
// Properly typed error with standardized code
const err = new Error('Module load failed');
err.code = 'EMODLOAD';
err.cause = error;
errorHandler(err);
});
// For error callbacks
service.use(
(config) => { /* ... */ },
(error) => {
// Properly handle error parameter
errorLogger(error);
throw error; // Propagate if needed
}
);