Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added bugsnags #262

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions app/actions/UploadInventory.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import RNFS from 'react-native-fs';
import {
getInventoryByStatus,
changeInventoryStatusAndLocationId,
changeInventoryStatus,
changeInventoryStatusAndLocationId,
getInventoryByStatus,
updateInventory,
} from '../repositories/inventory';
import RNFS from 'react-native-fs';
import { updateCount, updateIsUploading } from './inventory';
import dbLog from '../repositories/logs';
import { LogTypes } from '../utils/constants';
import { bugsnag } from '../utils';
import { permission } from '../utils/permissions';
import {
postAuthenticatedRequest,
getAuthenticatedRequest,
postAuthenticatedRequest,
putAuthenticatedRequest,
} from '../utils/api';
import { LogTypes } from '../utils/constants';
import {
MULTI,
OFF_SITE,
ON_SITE,
PENDING_DATA_UPLOAD,
Expand All @@ -24,8 +23,9 @@ import {
POLYGON,
SINGLE,
SYNCED,
MULTI,
} from '../utils/inventoryConstants';
import { permission } from '../utils/permissions';
import { updateCount, updateIsUploading } from './inventory';

const changeStatusAndUpload = async (response, oneInventory, dispatch) => {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -68,10 +68,9 @@ const changeStatusAndUpload = async (response, oneInventory, dispatch) => {
)
.then(() => resolve())
.catch((err) => {
console.error(
`Error at: /action/upload/changeInventoryStatus, -> ${JSON.stringify(err)}`,
);
console.error('Error at: /action/upload/changeInventoryStatus', err);
reject();
bugsnag.notify(err);
});
} else {
reject();
Expand All @@ -83,16 +82,14 @@ const changeStatusAndUpload = async (response, oneInventory, dispatch) => {
})
.catch((err) => {
reject(err);
console.error(
`Error at: /action/upload/changeInventoryStatusAndLocationId, -> ${JSON.stringify(
err,
)}`,
);
console.error('Error at: /action/upload/changeInventoryStatusAndLocationId, -> ', err);
bugsnag.notify(err);
});
}
} catch (err) {
reject(err);
console.error(`Error at: /action/upload/changeStatusAndUpload, -> ${JSON.stringify(err)}`);
bugsnag.notify(err);
console.error('Error at: /action/upload/changeStatusAndUpload, -> ', err);
}
});
};
Expand Down Expand Up @@ -157,9 +154,8 @@ export const uploadInventory = (dispatch) => {
updateIsUploading(false)(dispatch);
reject(err);
}
console.error(
`Error at: /action/upload, changeStatusAndUpload -> ${JSON.stringify(err)}`,
);
console.error('Error at: /action/upload, changeStatusAndUpload -> ', err);
bugsnag.notify(err);
});
} else {
if (inventoryData.length - 1 === i) {
Expand All @@ -173,23 +169,24 @@ export const uploadInventory = (dispatch) => {
reject(err);
}
console.error(
`Error at: /action/upload, POST - /treemapper/plantLocations -> ${JSON.stringify(
err.response,
)}`,
'Error at: /action/upload, POST - /treemapper/plantLocations -> ',
err.response,
);
dbLog.error({
logType: LogTypes.DATA_SYNC,
message: 'Error while add plant location, POST - /treemapper/plantLocations',
statusCode: err?.response?.status,
logStack: JSON.stringify(err.response),
});
bugsnag.notify(err);
}
}
}
})
.catch((err) => {
console.log(err);
reject(err);
bugsnag.notify(err);
return err;
});
});
Expand Down Expand Up @@ -324,6 +321,7 @@ const checkSampleTreesAndUpload = async (inventory) => {

await updateSampleTreeByIndex(inventory, sampleTree, index).catch((err) => {
console.error('Error while updating sample tree data', err);
bugsnag.notify(err);
});

const uploadResult = await uploadImage(
Expand All @@ -341,6 +339,7 @@ const checkSampleTreesAndUpload = async (inventory) => {
})
.catch((err) => {
console.error('Error while updating sample tree data', err);
bugsnag.notify(err);
});
} else {
console.error('Error while uploading image');
Expand All @@ -358,6 +357,7 @@ const checkSampleTreesAndUpload = async (inventory) => {
})
.catch((err) => {
console.error('Error while updating sample tree data', err);
bugsnag.notify(err);
});
}
} else {
Expand Down Expand Up @@ -426,7 +426,8 @@ const checkAndUploadImage = async (oneInventory, response) => {
// the length of coordinates of an inventory registration with the upload count of successfully completed upload
return { allUploadCompleted: completedUploadCount === responseCoords.length };
} catch (err) {
console.error(`Error at /actions/upload/checkAndUploadImage, ${JSON.stringify(err)}`);
bugsnag.notify(err);
console.error('Error at /actions/upload/checkAndUploadImage, -> ', err);
return { allUploadCompleted: false };
}
};
Expand Down Expand Up @@ -464,22 +465,21 @@ const uploadImage = async (imageUrl, locationId, coordinateId, inventoryId) => {
return true;
}
} catch (err) {
bugsnag.notify(err);
console.error(
`Error at: action/upload/uploadImage, PUT: ${locationId}/coordinates/${coordinateId} -> ${JSON.stringify(
err.response,
)}`,
`Error at: action/upload/uploadImage, PUT: ${locationId}/coordinates/${coordinateId} -> `,
err.response,
);
dbLog.error({
logType: LogTypes.DATA_SYNC,
message: `Error while uploading image for inventory id: ${inventoryId} and coordinate id: ${coordinateId}`,
logStack: JSON.stringify(err.response),
referenceId: inventoryId,
});
bugsnag.notify(err);
return false;
}
} catch (err) {
console.error(`Error at: action/upload/uploadImage, base64 image -> ${JSON.stringify(err)}`);
console.error('Error at: action/upload/uploadImage, base64 image -> ', err);
dbLog.error({
logType: LogTypes.DATA_SYNC,
message: `Error while fetching base64 image from file system for id: ${inventoryId} and coordinate id: ${coordinateId}`,
Expand Down Expand Up @@ -512,6 +512,7 @@ const getPlantLocationDetails = (locationId) => {
message: `Failed to fetch planted location details, GET - /treemapper/plantLocations/${locationId}.`,
logStack: JSON.stringify(err),
});
bugsnag.notify(err);
});
});
};
2 changes: 2 additions & 0 deletions app/actions/species.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const addUserSpecie = (specieData) => {
logStack: JSON.stringify(err?.response),
});
reject(err);
bugsnag.notify(err);
});
});
};
Expand Down Expand Up @@ -176,6 +177,7 @@ export const deleteUserSpecie = (specieId) => {
statusCode: err?.response?.status,
logStack: JSON.stringify(err?.response),
});
bugsnag.notify(err);
reject(err);
});
});
Expand Down
9 changes: 6 additions & 3 deletions app/actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,17 @@ export const auth0Login = (dispatch) => {
})
.catch((err) => {
reject(err);
bugsnag.notify(err);
});
})
.catch((err) => {
bugsnag.notify(err);
if (err?.error !== 'a0.session.user_cancelled') {
dbLog.error({
logType: LogTypes.USER,
message: 'Error while logging in from auth0',
logStack: JSON.stringify(err),
});
bugsnag.notify(err);
// if any error is found then deletes the user and clear the user app state
deleteUser();
clearUserDetails()(dispatch);
Expand Down Expand Up @@ -129,14 +130,14 @@ export const auth0Logout = (userDispatch = null) => {
resolve(true);
})
.catch((err) => {
bugsnag.notify(err);
if (err?.error !== 'a0.session.user_cancelled') {
console.error(`Error at /actions/user/auth0Logout, ${JSON.stringify(err)}`);
dbLog.error({
logType: LogTypes.USER,
message: 'Error while Logging Out',
logStack: JSON.stringify(err),
});
bugsnag.notify(err);
resolve(false);
} else {
dbLog.info({
Expand Down Expand Up @@ -255,7 +256,7 @@ export const getUserDetailsFromServer = (userToken, userDispatch = null) => {
err.response,
)}`,
);

bugsnag.notify(err);
dbLog.error({
logType: LogTypes.USER,
message: 'Failed to retrieve User Information from Server',
Expand Down Expand Up @@ -298,6 +299,7 @@ export const SignupService = (payload, dispatch) => {
message: 'Failed to Sign up',
statusCode: err?.response?.status,
});
bugsnag.notify(err);
// if any error is found then deletes the user and clear the user app state
deleteUser();
clearUserDetails()(dispatch);
Expand Down Expand Up @@ -342,6 +344,7 @@ export const getCdnUrls = (language = 'en') => {
logStack: JSON.stringify(err?.response),
});
resolve(false);
bugsnag.notify(err);
});
});
};
Expand Down
16 changes: 11 additions & 5 deletions app/components/Common/Camera/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import React, { useRef } from 'react';
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
import {RNCamera} from 'react-native-camera';
import { RNCamera } from 'react-native-camera';
import Icon from 'react-native-vector-icons/FontAwesome';
import i18next from 'i18next';
import { bugsnag } from '../../../utils';

export default function index({handleCamera}) {
export default function index({ handleCamera }) {
const camera = useRef();
// const [imagePath, setImagePath] = useState(null);

const takePicture =async () => {
const takePicture = async () => {
const options = { quality: 0.5 };
const data = await camera.current.takePictureAsync(options).catch((err) => {
alert(i18next.t('label.permission_camera_message'));
bugsnag.notify(err);
});
// setImagePath(data.uri);
handleCamera(data.uri);
Expand All @@ -21,8 +23,12 @@ export default function index({handleCamera}) {
ratio={'1:1'}
captureAudio={false}
ref={camera}
style={{flex: 1}}
notAuthorizedView={(<View><Text>{i18next.t('label.permission_camera_message')}</Text></View>)}
style={{ flex: 1 }}
notAuthorizedView={
<View>
<Text>{i18next.t('label.permission_camera_message')}</Text>
</View>
}
androidCameraPermissionOptions={{
title: i18next.t('label.permission_camera_title'),
message: i18next.t('label.permission_camera_message'),
Expand Down
4 changes: 4 additions & 0 deletions app/components/Common/ImageCapturing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
updateLastScreen,
} from '../../../repositories/inventory';
import dbLog from '../../../repositories/logs';
import { bugsnag } from '../../../utils';
import { LogTypes } from '../../../utils/constants';
import { MULTI, ON_SITE } from '../../../utils/inventoryConstants';
import { toLetters } from '../../../utils/mapMarkingCoordinate';
Expand Down Expand Up @@ -128,6 +129,7 @@ const ImageCapturing = ({
return data;
} catch (err) {
console.error('error while saving file', err);
bugsnag.notify(err);
}
};

Expand All @@ -140,6 +142,7 @@ const ImageCapturing = ({
const data = await camera.current.takePictureAsync(options).catch((err) => {
alert(i18next.t('label.permission_camera_message'));
setImagePath('');
bugsnag.notify(err);
return;
});
if (data) {
Expand Down Expand Up @@ -215,6 +218,7 @@ const ImageCapturing = ({
}
} catch (err) {
console.error('error while saving file', err);
bugsnag.notify(err);
}
} else {
alert(i18next.t('label.image_capturing_required'));
Expand Down
4 changes: 3 additions & 1 deletion app/components/Common/SpeciesSyncError/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import AsyncStorage from '@react-native-community/async-storage';
import Snackbar from 'react-native-snackbar';
import { Colors, Typography } from '_styles';
import i18next from 'i18next';
import { bugsnag } from '../../../utils';

//Component which will be rendered on Mainscreen and Managespecies when species are not synced or downloaded
const SpeciesSyncError = () => {
Expand All @@ -29,8 +30,9 @@ const SpeciesSyncError = () => {
const species = await AsyncStorage.getItem('isLocalSpeciesUpdated');
setAsyncStorageSpecies(species);
})
.catch(() => {
.catch((err) => {
setRefreshAnimation(false);
bugsnag.notify(err);
Snackbar.show({
text: i18next.t('label.snackBarText'),
duration: Snackbar.LENGTH_SHORT,
Expand Down
2 changes: 2 additions & 0 deletions app/components/Common/Syncing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { InventoryContext } from '../../../reducers/inventory';
import i18next from 'i18next';
import { UserContext } from '../../../reducers/user';
import { useNavigation } from '@react-navigation/native';
import { bugsnag } from '../../../utils';

export default function Syncing({ uploadCount, pendingCount, isUploading, isUserLogin }) {
const [syncText, setSyncText] = useState('');
Expand Down Expand Up @@ -59,6 +60,7 @@ export default function Syncing({ uploadCount, pendingCount, isUploading, isUser
{ cancelable: false },
);
}
bugsnag.notify(err);
});
};

Expand Down
4 changes: 4 additions & 0 deletions app/components/DownloadMap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Geolocation from 'react-native-geolocation-service';
import Icon from 'react-native-vector-icons/MaterialIcons';
import { Colors, Typography } from '_styles';
import { createOfflineMap, getAllOfflineMaps, getAreaName } from '../../repositories/maps';
import { bugsnag } from '../../utils';
import { permission } from '../../utils/permissions';
import { AlertModal, Header, PrimaryButton } from '../Common';

Expand Down Expand Up @@ -76,6 +77,7 @@ const DownloadMap = ({ navigation }) => {
);
})
.catch((err) => {
bugsnag.notify(err);
if (err === 'blocked') {
setIsPermissionBlockedAlertShow(true);
}
Expand Down Expand Up @@ -110,6 +112,7 @@ const DownloadMap = ({ navigation }) => {
.catch((err) => {
setIsLoaderShow(false);
setAreaName('');
bugsnag.notify(err);
alert(i18next.t('label.download_map_area_exists'));
});
}
Expand All @@ -136,6 +139,7 @@ const DownloadMap = ({ navigation }) => {
.catch((err) => {
setIsLoaderShow(false);
setAreaName('');
bugsnag.notify(err);
alert(i18next.t('label.download_map_area_failed'));
});
};
Expand Down
Loading