Last active
August 23, 2019 23:56
-
-
Save ryan2clw/8299981750c35d9b420c74ac9e41a5a1 to your computer and use it in GitHub Desktop.
Events for bingo game aka actionTypes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum actionTypes { | |
/* Messaging system */ | |
ALERT_SUCCESS = 'ALERT_SUCCESS', | |
ALERT_DANGER = 'ALERT_DANGER', | |
ALERT_CLEAR = 'ALERT_CLEAR', | |
/* Bingo cards */ | |
CARD_REQUEST = 'CARD_REQUEST', | |
CARD_SUCCESS = 'CARD_SUCCESS', | |
CARD_FAILURE = 'CARD_FAILURE', | |
} | |
export default actionTypes; | |
export interface IResponse { | |
statusText: string, | |
ok: boolean | |
text(): Promise<string>, | |
} | |
/* Global parsing and error handling for AJAX requests */ | |
export const handleResponse = (response: IResponse) => { | |
return response.text().then((text) => { | |
console.log("handleResponse", text); | |
const data = text && JSON.parse(text); | |
if (!response.ok) { | |
const error = (data && data.message) || response.statusText; | |
return Promise.reject(error); | |
} | |
return data; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment