Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fetch(api.SEARCH_THE_ACCOUNT_ENDPOINT + "username=" + this.state.email, {
- method: 'GET',
- headers: {
- 'access_token': access_token
- },
- // body: formBody
- }).then((response) => {
- if (response.status >= 200 && response.status < 300) {
- return response.json();
- } else {
- return Promise.reject({ status: response.status, body: response.body });
- }
- }).then((responseJson) => {
- console.log("Fetch Response");
- console.log(responseJson);
- }).catch((error) => {
- // error = { status: response.status, body: response.body }
- if (error.status === 400 && error.body.status === 'TooManyPunch') {
- // do something
- } else if (error.status === 400 && error.body.status === 'UsernameFormatError') {
- // do something
- } else {
- console.log('I also dont know what is this going on :(');
- }
- });
- //--------------------------------------
- fetch(api.SEARCH_THE_ACCOUNT_ENDPOINT + "username=" + this.state.email, {
- method: 'GET',
- headers: {
- 'access_token': access_token
- },
- // body: formBody
- }).then((response) => {
- if (response.status === 500) {
- return Promise.reject(500);
- } else {
- return response.json().then(responseJson => {
- return { status: response.status, json: responseJson };
- });
- }
- }).then((response) => {
- // response.status, response.json
- if (response.status === 400 && response.json.status === 'TooManyPunch') {
- // do something
- } else if (response.status === 400 && response.json.status === 'UsernameFormatError') {
- // do something
- } else { // = status 2XX
- // do normal thing
- }
- }).catch((error) => {
- if (error === 500) {
- // 500 Error Handling
- } else {
- // Unknown Error Handling, e.g. response.json() failed
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement