From 080e76350c2570eeb096fad40fe95f1b766b4539 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 11 Jan 2021 16:11:11 -0500 Subject: created strings.ts and linting --- src/services/MomentServices.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src/services/MomentServices.ts') diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts index 91ecf712..76f353ce 100644 --- a/src/services/MomentServices.ts +++ b/src/services/MomentServices.ts @@ -1,6 +1,7 @@ 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} from '../constants/strings'; import {MomentType} from '../types'; import {checkImageUploadStatus} from '../utils'; @@ -48,20 +49,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 {}; } }; -- cgit v1.2.3-70-g09d2