Skip to content

Instantly share code, notes, and snippets.

@ryan2clw
Last active August 23, 2019 23:56
Show Gist options
  • Save ryan2clw/8299981750c35d9b420c74ac9e41a5a1 to your computer and use it in GitHub Desktop.
Save ryan2clw/8299981750c35d9b420c74ac9e41a5a1 to your computer and use it in GitHub Desktop.
Events for bingo game aka actionTypes
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