add centralized error handling and improve Google Auth error logging

This commit is contained in:
bobbert committed 2026-02-24 23:23:53 +00:00
1 parent 0ef59ba5d3
commit f6c61ab829
5 files changed
+175 -161

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
import { Alert } from 'react-native';
/**
* Centralised error handler for the app.
*
* Usage:
* import { logError, alertError } from '../services/ErrorHandler';
*
* logError('Google Auth', error); // console.error only
* alertError('Upload Failed', error); // Alert + console.error
*/
/**
* Log an error to the console with a contextual tag.
* @param {string} tag – short label, e.g. 'Google Auth', 'NAS'
* @param {Error|string} error
*/
export const logError = (tag, error) => {
const message = error instanceof Error ? error.message : String(error);
console.error(`[${tag}] ${message}`);
};
/**
* Show a user-facing Alert AND log to the console.
* @param {string} title – Alert title
* @param {Error|string} error
* @param {Array} [buttons] – optional Alert button array
*/
export const alertError = (title, error, buttons) => {
const message = error instanceof Error ? error.message : String(error);
console.error(`[${title}] ${message}`);
Alert.alert(title, message, buttons || [{ text: 'OK' }]);
};
export default { logError, alertError };