1+ import { WeaviateUnexpectedStatusCodeError } from '../errors.js' ;
12import { ConnectionREST } from '../index.js' ;
23import {
34 WeaviateUserTypeInternal as UserTypeInternal ,
@@ -102,8 +103,14 @@ const users = (connection: ConnectionREST): Users => {
102103const db = ( connection : ConnectionREST ) : DBUsers => {
103104 const ns = namespacedUsers ( connection ) ;
104105
105- const allowCode = ( code : number ) : ( ( reason : any ) => boolean ) => {
106- return ( reason ) => reason . code !== undefined && reason . code === code ;
106+ /** expectCode returns true if the error contained an expected status code. */
107+ const expectCode = ( code : number ) : ( ( _ : any ) => boolean ) => {
108+ return ( error ) => {
109+ if ( error instanceof WeaviateUnexpectedStatusCodeError ) {
110+ return error . code === code ;
111+ }
112+ throw error ;
113+ }
107114 } ;
108115
109116 type APIKeyResponse = { apikey : string } ;
@@ -128,12 +135,12 @@ const db = (connection: ConnectionREST): DBUsers => {
128135 connection
129136 . postEmpty < null > ( `/users/db/${ userId } /activate` , null )
130137 . then ( ( ) => true )
131- . catch ( allowCode ( 409 ) ) ,
138+ . catch ( expectCode ( 409 ) ) ,
132139 deactivate : ( userId : string ) =>
133140 connection
134141 . postEmpty < null > ( `/users/db/${ userId } /deactivate` , null )
135142 . then ( ( ) => true )
136- . catch ( allowCode ( 409 ) ) ,
143+ . catch ( expectCode ( 409 ) ) ,
137144 byName : ( userId : string ) => connection . get < WeaviateDBUser > ( `/users/db/${ userId } ` , true ) . then ( Map . dbUser ) ,
138145 listAll : ( ) => connection . get < WeaviateDBUser [ ] > ( '/users/db' , true ) . then ( Map . dbUsers ) ,
139146 } ;
0 commit comments