@@ -125,7 +125,7 @@ func (h Search) UpsertIndex(
125125	opts  * UpsertIndexOptions ,
126126) (* UpsertIndexResponse , error ) {
127127	if  opts .Name  ==  ""  {
128- 		return  nil , errors . New ( "must specify index name when creating an index" ) 
128+ 		return  nil , ErrIndexNameEmpty 
129129	}
130130	if  opts .Type  ==  ""  {
131131		return  nil , errors .New ("must specify index type when creating an index" )
@@ -139,7 +139,7 @@ func (h Search) UpsertIndex(
139139		reqURI  =  fmt .Sprintf ("/api/index/%s" , opts .Name )
140140	} else  {
141141		if  opts .ScopeName  ==  ""  ||  opts .BucketName  ==  ""  {
142- 			return  nil , errors . New ( "must specify both or neither of scope and bucket names" ) 
142+ 			return  nil , ErrOnlyBucketOrScopeSet 
143143		}
144144		reqURI  =  fmt .Sprintf ("/api/bucket/%s/scope/%s/index/%s" , opts .BucketName , opts .ScopeName , opts .Name )
145145	}
@@ -188,15 +188,15 @@ func (h Search) DeleteIndex(
188188	opts  * DeleteIndexOptions ,
189189) error  {
190190	if  opts .IndexName  ==  ""  {
191- 		return  errors . New ( "must specify index name when deleting an index" ) 
191+ 		return  ErrIndexNameEmpty 
192192	}
193193
194194	var  reqURI  string 
195195	if  opts .ScopeName  ==  ""  &&  opts .BucketName  ==  ""  {
196196		reqURI  =  fmt .Sprintf ("/api/index/%s" , opts .IndexName )
197197	} else  {
198198		if  opts .ScopeName  ==  ""  ||  opts .BucketName  ==  ""  {
199- 			return  errors . New ( "must specify both or neither of scope and bucket names" ) 
199+ 			return  ErrOnlyBucketOrScopeSet 
200200		}
201201		reqURI  =  fmt .Sprintf ("/api/bucket/%s/scope/%s/index/%s" , opts .BucketName , opts .ScopeName , opts .IndexName )
202202	}
@@ -235,15 +235,15 @@ func (h Search) GetIndex(
235235	opts  * GetIndexOptions ,
236236) (* Index , error ) {
237237	if  opts .IndexName  ==  ""  {
238- 		return  nil , errors . New ( "must specify index name when getting an index" ) 
238+ 		return  nil , ErrIndexNameEmpty 
239239	}
240240
241241	var  reqURI  string 
242242	if  opts .ScopeName  ==  ""  &&  opts .BucketName  ==  ""  {
243243		reqURI  =  fmt .Sprintf ("/api/index/%s" , opts .IndexName )
244244	} else  {
245245		if  opts .ScopeName  ==  ""  ||  opts .BucketName  ==  ""  {
246- 			return  nil , errors . New ( "must specify both or neither of scope and bucket names" ) 
246+ 			return  nil , ErrOnlyBucketOrScopeSet 
247247		}
248248		reqURI  =  fmt .Sprintf ("/api/bucket/%s/scope/%s/index/%s" , opts .BucketName , opts .ScopeName , opts .IndexName )
249249	}
@@ -295,7 +295,7 @@ func (h Search) GetAllIndexes(
295295		reqURI  =  "/api/index/" 
296296	} else  {
297297		if  opts .ScopeName  ==  ""  ||  opts .BucketName  ==  ""  {
298- 			return  nil , errors . New ( "must specify both or neither of scope and bucket names" ) 
298+ 			return  nil , ErrOnlyBucketOrScopeSet 
299299		}
300300		reqURI  =  fmt .Sprintf ("/api/bucket/%s/scope/%s/index" , opts .BucketName , opts .ScopeName )
301301	}
@@ -353,15 +353,15 @@ func (h Search) AnalyzeDocument(
353353	opts  * AnalyzeDocumentOptions ,
354354) (* DocumentAnalysis , error ) {
355355	if  opts .IndexName  ==  ""  {
356- 		return  nil , errors . New ( "must specify index name when analyzing a document" ) 
356+ 		return  nil , ErrIndexNameEmpty 
357357	}
358358
359359	var  reqURI  string 
360360	if  opts .ScopeName  ==  ""  &&  opts .BucketName  ==  ""  {
361361		reqURI  =  fmt .Sprintf ("/api/index/%s/analyzeDoc" , opts .IndexName )
362362	} else  {
363363		if  opts .ScopeName  ==  ""  ||  opts .BucketName  ==  ""  {
364- 			return  nil , errors . New ( "must specify both or neither of scope and bucket names" ) 
364+ 			return  nil , ErrOnlyBucketOrScopeSet 
365365		}
366366		reqURI  =  fmt .Sprintf ("/api/index/%s.%s.%s/analyzeDoc" , opts .BucketName , opts .ScopeName , opts .IndexName )
367367	}
@@ -406,15 +406,15 @@ func (h Search) GetIndexedDocumentsCount(
406406	opts  * GetIndexedDocumentsCountOptions ,
407407) (uint64 , error ) {
408408	if  opts .IndexName  ==  ""  {
409- 		return  0 , errors . New ( "must specify index name when analyzing a document" ) 
409+ 		return  0 , ErrIndexNameEmpty 
410410	}
411411
412412	var  reqURI  string 
413413	if  opts .ScopeName  ==  ""  &&  opts .BucketName  ==  ""  {
414414		reqURI  =  fmt .Sprintf ("/api/index/%s/count" , opts .IndexName )
415415	} else  {
416416		if  opts .ScopeName  ==  ""  ||  opts .BucketName  ==  ""  {
417- 			return  0 , errors . New ( "must specify both or neither of scope and bucket names" ) 
417+ 			return  0 , ErrOnlyBucketOrScopeSet 
418418		}
419419		reqURI  =  fmt .Sprintf ("/api/bucket/%s/scope/%s/index/%s/count" , opts .BucketName , opts .ScopeName , opts .IndexName )
420420	}
@@ -534,15 +534,15 @@ func (h Search) controlRequest(
534534	onBehalfOf  * cbhttpx.OnBehalfOfInfo ,
535535) error  {
536536	if  indexName  ==  ""  {
537- 		return  errors . New ( "must specify index name" ) 
537+ 		return  ErrIndexNameEmpty 
538538	}
539539
540540	var  reqURI  string 
541541	if  scopeName  ==  ""  &&  bucketName  ==  ""  {
542542		reqURI  =  fmt .Sprintf ("/api/index/%s/%s" , indexName , control )
543543	} else  {
544544		if  scopeName  ==  ""  ||  bucketName  ==  ""  {
545- 			return  errors . New ( "must specify both or neither of scope and bucket names" ) 
545+ 			return  ErrOnlyBucketOrScopeSet 
546546		}
547547		reqURI  =  fmt .Sprintf ("/api/bucket/%s/scope/%s/index/%s/%s" , bucketName , scopeName , indexName , control )
548548	}
@@ -607,10 +607,14 @@ func (h Search) DecodeCommonError(resp *http.Response) error {
607607	var  err  error 
608608	errText  :=  strings .ToLower (string (bodyBytes ))
609609
610- 	if  strings .Contains (errText , "index not found" ) {
610+ 	if  strings .Contains (errText , "index not found" ) ||   strings . Contains ( errText ,  "index missing for update" )  {
611611		err  =  ErrIndexNotFound 
612612	} else  if  strings .Contains (errText , "index with the same name already exists" ) {
613613		err  =  ErrIndexExists 
614+ 	} else  if  strings .Contains (errText , "indexname is invalid" ) {
615+ 		err  =  ErrIndexNameInvalid 
616+ 	} else  if  strings .Contains (errText , "index name is too long" ) {
617+ 		err  =  ErrIndexNameTooLong 
614618	} else  if  strings .Contains (errText , "current index uuid" ) &&  strings .Contains (errText , "did not match input uuid" ) {
615619		err  =  ErrIndexExists 
616620	} else  if  strings .Contains (errText , "unknown indextype" ) {
0 commit comments