diff options
| author | Ivan Chen <ivan@thetaggid.com> | 2021-01-15 19:27:03 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-15 19:27:03 -0500 |
| commit | 1803da7388902db45ad37fbac509604ae632bdb5 (patch) | |
| tree | a786919f9bc42f7797367d55ed8f1e099134f368 /src/services/MomentServices.ts | |
| parent | 4d9efafeb4243e20e1fc936c27b9055c7ec82f8a (diff) | |
| parent | cc52dabaaf529763e9c1c4683ba94ed55c5671a8 (diff) | |
Merge pull request #176 from IvanIFChen/tma498-update-error-strings
[TMA-498] Update Error Strings
Diffstat (limited to 'src/services/MomentServices.ts')
| -rw-r--r-- | src/services/MomentServices.ts | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts index 91ecf712..217b5857 100644 --- a/src/services/MomentServices.ts +++ b/src/services/MomentServices.ts @@ -1,6 +1,11 @@ import AsyncStorage from '@react-native-community/async-storage'; import {Alert} from 'react-native'; import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants'; +import { + ERROR_FAILED_TO_COMMENT, + ERROR_UPLOAD, + SUCCESS_PIC_UPLOAD, +} from '../constants/strings'; import {MomentType} from '../types'; import {checkImageUploadStatus} from '../utils'; @@ -48,20 +53,12 @@ export const postMomentComment = async ( }, body: request, }); - const status = response.status; - if (status === 200) { - const response_data = await response.json(); - return response_data; - } else { - Alert.alert('Something went wrong! ðŸ˜', 'Not able to post a comment'); - return {}; + if (response.status !== 200) { + throw 'server error'; } + return await response.json(); } catch (error) { - Alert.alert( - 'Something went wrong! ðŸ˜', - 'Not able to post a comment', - error, - ); + Alert.alert(ERROR_FAILED_TO_COMMENT); return {}; } }; @@ -136,15 +133,15 @@ export const postMoment: ( }); let statusCode = response.status; let data = await response.json(); - if (statusCode === 200 && checkImageUploadStatus(data['moments'])) { - Alert.alert('The picture was uploaded successfully!'); - return data['profile_completion_stage']; + if (statusCode === 200 && checkImageUploadStatus(data.moments)) { + Alert.alert(SUCCESS_PIC_UPLOAD); + return data.profile_completion_stage; } else { - Alert.alert('An error occured while uploading. Please try again!'); + Alert.alert(ERROR_UPLOAD); } } catch (err) { console.log(err); - Alert.alert('An error occured during authenticaion. Please login again!'); + Alert.alert(ERROR_UPLOAD); } return undefined; }; |
