1 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 // use this file except in compliance with the License. You may obtain a copy of 3 // the License at 4 // 5 // http://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 // License for the specific language governing permissions and limitations under 11 // the License. 12 13 package kivik 14 15 import ( 16 internal "github.com/go-kivik/kivik/v4/int/errors" 17 ) 18 19 const ( 20 // ErrClientClosed is returned by any client operations after [Client.Close] 21 // has been called. 22 ErrClientClosed = internal.CompositeError("503 client closed") 23 // ErrDatabaseClosed is returned by any database operations after [DB.Close] 24 // has been called. 25 ErrDatabaseClosed = internal.CompositeError("503 database closed") 26 27 // Various not-implemented errors, that are returned, but don't need to be exposed directly. 28 errFindNotImplemented = internal.CompositeError("501 driver does not support Find interface") 29 errClusterNotImplemented = internal.CompositeError("501 driver does not support cluster operations") 30 errOpenRevsNotImplemented = internal.CompositeError("501 driver does not support OpenRevs interface") 31 errSecurityNotImplemented = internal.CompositeError("501 driver does not support Security interface") 32 errConfigNotImplemented = internal.CompositeError("501 driver does not support Config interface") 33 errReplicationNotImplemented = internal.CompositeError("501 driver does not support replication") 34 errNoAttachments = internal.CompositeError("404 no attachments") 35 ) 36 37 // HTTPStatus returns the HTTP status code embedded in the error, or 500 38 // (internal server error), if there was no specified status code. If err is 39 // nil, HTTPStatus returns 0. This provides a convenient way to determine the 40 // precise nature of a Kivik-returned error. 41 // 42 // For example, to panic for all but NotFound errors: 43 // 44 // err := db.Get(context.TODO(), "docID").ScanDoc(&doc) 45 // if kivik.HTTPStatus(err) == http.StatusNotFound { 46 // return 47 // } 48 // if err != nil { 49 // panic(err) 50 // } 51 // 52 // This method uses the statusCoder interface, which is not exported by this 53 // package, but is considered part of the stable public API. Driver 54 // implementations are expected to return errors which conform to this 55 // interface. 56 // 57 // type statusCoder interface { 58 // HTTPStatus() int 59 // } 60 func HTTPStatus(err error) int { 61 return internal.HTTPStatus(err) 62 } 63