@@ -116,10 +116,14 @@ export default class ConnectionREST {
116116 postReturn = < B , T > ( path : string , payload : B ) : Promise < T > => {
117117 if ( this . authEnabled ) {
118118 return this . login ( ) . then ( ( token ) =>
119- this . http . post < B , T > ( path , payload , true , token ) . then ( ( res ) => res as T )
119+ this . http . post < B , T > ( path , payload , true , token ) as T
120120 ) ;
121121 }
122- return this . http . post < B , T > ( path , payload , true , '' ) . then ( ( res ) => res as T ) ;
122+ return this . http . post < B , T > ( path , payload , true , '' ) as Promise < T > ;
123+ } ;
124+
125+ postNoBody = < T > ( path : string ) : Promise < T > => {
126+ return this . postReturn < null , T > ( path , null ) ;
123127 } ;
124128
125129 postEmpty = < B > ( path : string , payload : B ) : Promise < void > => {
@@ -372,46 +376,46 @@ const makeUrl = (basePath: string) => (path: string) => basePath + path;
372376
373377const checkStatus =
374378 < T > ( expectResponseBody : boolean ) =>
375- ( res : Response ) => {
376- if ( res . status >= 400 ) {
377- return res . text ( ) . then ( ( errText : string ) => {
378- let err : string ;
379- try {
380- // in case of invalid json response (like empty string)
381- err = JSON . stringify ( JSON . parse ( errText ) ) ;
382- } catch ( e ) {
383- err = errText ;
384- }
385- if ( res . status === 401 ) {
386- return Promise . reject ( new WeaviateUnauthenticatedError ( err ) ) ;
387- } else if ( res . status === 403 ) {
388- return Promise . reject ( new WeaviateInsufficientPermissionsError ( 403 , err ) ) ;
389- } else {
390- return Promise . reject ( new WeaviateUnexpectedStatusCodeError ( res . status , err ) ) ;
391- }
392- } ) ;
393- }
394- if ( expectResponseBody ) {
395- return res . json ( ) as Promise < T > ;
396- }
397- return Promise . resolve ( undefined ) ;
398- } ;
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+ } ;
399403
400404const handleHeadResponse =
401405 < T > ( expectResponseBody : boolean ) =>
402- ( res : Response ) => {
403- if ( res . status == 200 || res . status == 204 || res . status == 404 ) {
404- return Promise . resolve ( res . status == 200 || res . status == 204 ) ;
405- }
406- return checkStatus < T > ( expectResponseBody ) ( res ) ;
407- } ;
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+ } ;
408412
409413const getAuthHeaders = ( config : InternalConnectionParams , bearerToken : string ) =>
410414 bearerToken
411415 ? {
412- Authorization : `Bearer ${ bearerToken } ` ,
413- 'X-Weaviate-Cluster-Url' : config . host ,
414- // keeping for backwards compatibility for older clusters for now. On newer clusters, Embedding Service reuses Authorization header.
415- 'X-Weaviate-Api-Key' : bearerToken ,
416- }
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+ }
417421 : undefined ;
0 commit comments