@@ -115,9 +115,7 @@ export default class ConnectionREST {
115115
116116 postReturn = < B , T > ( path : string , payload : B ) : Promise < T > => {
117117 if ( this . authEnabled ) {
118- return this . login ( ) . then ( ( token ) =>
119- this . http . post < B , T > ( path , payload , true , token ) as T
120- ) ;
118+ return this . login ( ) . then ( ( token ) => this . http . post < B , T > ( path , payload , true , token ) as T ) ;
121119 }
122120 return this . http . post < B , T > ( path , payload , true , '' ) as Promise < T > ;
123121 } ;
@@ -376,46 +374,46 @@ const makeUrl = (basePath: string) => (path: string) => basePath + path;
376374
377375const checkStatus =
378376 < T > ( expectResponseBody : boolean ) =>
379- ( res : Response ) => {
380- if ( res . status >= 400 ) {
381- return res . text ( ) . then ( ( errText : string ) => {
382- let err : string ;
383- try {
384- // in case of invalid json response (like empty string)
385- err = JSON . stringify ( JSON . parse ( errText ) ) ;
386- } catch ( e ) {
387- err = errText ;
388- }
389- if ( res . status === 401 ) {
390- return Promise . reject ( new WeaviateUnauthenticatedError ( err ) ) ;
391- } else if ( res . status === 403 ) {
392- return Promise . reject ( new WeaviateInsufficientPermissionsError ( 403 , err ) ) ;
393- } else {
394- return Promise . reject ( new WeaviateUnexpectedStatusCodeError ( res . status , err ) ) ;
395- }
396- } ) ;
397- }
398- if ( expectResponseBody ) {
399- return res . json ( ) as Promise < T > ;
400- }
401- return Promise . resolve ( undefined ) ;
402- } ;
377+ ( res : Response ) => {
378+ if ( res . status >= 400 ) {
379+ return res . text ( ) . then ( ( errText : string ) => {
380+ let err : string ;
381+ try {
382+ // in case of invalid json response (like empty string)
383+ err = JSON . stringify ( JSON . parse ( errText ) ) ;
384+ } catch ( e ) {
385+ err = errText ;
386+ }
387+ if ( res . status === 401 ) {
388+ return Promise . reject ( new WeaviateUnauthenticatedError ( err ) ) ;
389+ } else if ( res . status === 403 ) {
390+ return Promise . reject ( new WeaviateInsufficientPermissionsError ( 403 , err ) ) ;
391+ } else {
392+ return Promise . reject ( new WeaviateUnexpectedStatusCodeError ( res . status , err ) ) ;
393+ }
394+ } ) ;
395+ }
396+ if ( expectResponseBody ) {
397+ return res . json ( ) as Promise < T > ;
398+ }
399+ return Promise . resolve ( undefined ) ;
400+ } ;
403401
404402const handleHeadResponse =
405403 < T > ( expectResponseBody : boolean ) =>
406- ( res : Response ) => {
407- if ( res . status == 200 || res . status == 204 || res . status == 404 ) {
408- return Promise . resolve ( res . status == 200 || res . status == 204 ) ;
409- }
410- return checkStatus < T > ( expectResponseBody ) ( res ) ;
411- } ;
404+ ( res : Response ) => {
405+ if ( res . status == 200 || res . status == 204 || res . status == 404 ) {
406+ return Promise . resolve ( res . status == 200 || res . status == 204 ) ;
407+ }
408+ return checkStatus < T > ( expectResponseBody ) ( res ) ;
409+ } ;
412410
413411const getAuthHeaders = ( config : InternalConnectionParams , bearerToken : string ) =>
414412 bearerToken
415413 ? {
416- Authorization : `Bearer ${ bearerToken } ` ,
417- 'X-Weaviate-Cluster-Url' : config . host ,
418- // keeping for backwards compatibility for older clusters for now. On newer clusters, Embedding Service reuses Authorization header.
419- 'X-Weaviate-Api-Key' : bearerToken ,
420- }
414+ Authorization : `Bearer ${ bearerToken } ` ,
415+ 'X-Weaviate-Cluster-Url' : config . host ,
416+ // keeping for backwards compatibility for older clusters for now. On newer clusters, Embedding Service reuses Authorization header.
417+ 'X-Weaviate-Api-Key' : bearerToken ,
418+ }
421419 : undefined ;
0 commit comments