Advertisement
Guest User

Untitled

a guest
Dec 29th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. - @Injectable() export class ConstantService {
  2.  
  3.  
  4. constructor(private router: Router, private _logger: Logger) { }
  5.  
  6. public WEBSERVICE_URL: string = "http://localhost:8081/abcd/";
  7.  
  8. public OAUTH2_CLIENT_USERNAME: string =
  9. "springbootproj-trusted-client"; public OAUTH2_CLIENT_PASSWORD:
  10. string = "secret";
  11.  
  12. public MESSAGE_ACCESSTOKEN_EXPIRED: string = "Looks like your
  13. access token has been expired. Please login."; public
  14. MESSAGE_INTERNAL_SERVER_ERROR: string = "Some internal server error
  15. has occured. Please try again. If problem persists then please
  16. contact Administrator."; public MESSAGE_NO_RECORDFOUND_ERROR:
  17. string = "No records found.";
  18.  
  19. public handleError = function (error: Response) {
  20. let errMsg = error.json().error || 'Server error';
  21. this._logger.error("Error",errMsg);
  22. // console.error("Response error: " + errMsg);
  23.  
  24. if (error.status === 0) {
  25. alert(this.MESSAGE_ACCESSTOKEN_EXPIRED);
  26. this.router.navigate(['/login']);
  27. } else if (error.status === 500) {
  28. alert(this.MESSAGE_INTERNAL_SERVER_ERROR);
  29. }
  30. return Observable.throw(error.json().error || 'Server error'); }.bind(this);
  31.  
  32. public extractData = function (res: Response) {
  33. if (res.status === 204) {
  34. alert(this.MESSAGE_NO_RECORDFOUND_ERROR);
  35. } else {
  36. let body: any;
  37. if (res.text()) {
  38. body = res.json();
  39. }
  40. return body || {};
  41. } }.bind(this) }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement