mirror of
https://github.com/mudabbir-ahmad/Media-Aggregation-and-Sorting-System.git
synced 2026-10-07 19:40:20 +00:00
add centralized error handling and improve Google Auth error logging
This commit is contained in:
1 parent
0ef59ba5d3
commit
f6c61ab829
5 files changed
+175
-161
No files matched your search
@@ -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 };
|
||||
|
||||
Reference in new issue
Block a user