1- import { usersService } from ' ../services'
2- import { User } from ' ../types' ;
1+ import { usersService } from " ../services" ;
2+ import { User } from " ../types" ;
33
44export function authHeader ( ) {
5- // return authorization header with jwt token
6- const userString = localStorage . getItem ( 'user' )
7- if ( userString ) {
8- const user : User = JSON . parse ( userString ) ;
9- if ( user && user . token ) {
10- return { 'Authorization' : 'Bearer ' + user . token } ;
11- }
5+ // return authorization header with jwt token
6+ const userString = localStorage . getItem ( "user" ) ;
7+ if ( userString ) {
8+ const user : User = JSON . parse ( userString ) ;
9+ if ( user && user . token ) {
10+ return { Authorization : "Bearer " + user . token } ;
1211 }
13- return [ ] ;
12+ }
13+ return [ ] ;
1414}
1515
1616export function handleResponse ( response : Response ) {
17- return response . text ( ) . then ( ( text : string ) => {
18- const data = text && JSON . parse ( text ) ;
19- if ( ! response . ok ) {
20- if ( response . status === 401 ) {
21- // auto logout if 401 response returned from api
22- usersService . logout ( ) ;
23- window . location . reload ( ) ;
24- }
17+ return response . text ( ) . then ( ( text : string ) => {
18+ const data = text && JSON . parse ( text ) ;
19+ if ( ! response . ok ) {
20+ if ( response . status === 401 ) {
21+ // auto logout if 401 response returned from api
22+ usersService . logout ( ) ;
23+ window . location . reload ( ) ;
24+ }
2525
26- const error = ( data && data . message ) || response . statusText ;
27- return Promise . reject ( error ) ;
28- }
26+ const error = ( data && data . message ) || response . statusText ;
27+ return Promise . reject ( error ) ;
28+ }
2929
30- return data ;
31- } ) ;
32- }
30+ return data ;
31+ } ) ;
32+ }
0 commit comments