Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import { authenticationService } from '../_services/authentication.service';
  2.  
  3. export function handleResponse(response) {
  4. return response.text().then(text => {
  5. let data = text && JSON.parse(text);
  6. if (!response.ok) {
  7. if ([401, 403].indexOf(response.status) !== -1) {
  8. // auto logout if 401 Unauthorized or 403 Forbidden response returned from api
  9. authenticationService.logout();
  10. window.location.reload(true);
  11. }
  12.  
  13. const error = (data && data.message) || response.statusText;
  14. return Promise.reject(error);
  15. }
  16.  
  17. return data;
  18. });
  19. }
  20.  
  21. export default handleResponse;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement