github.com/weaviate/weaviate@v1.24.6/usecases/objects/errors.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package objects 13 14 import ( 15 "fmt" 16 ) 17 18 // objects status code 19 const ( 20 StatusForbidden = 403 21 StatusBadRequest = 400 22 StatusNotFound = 404 23 StatusUnprocessableEntity = 422 24 StatusInternalServerError = 500 25 ) 26 27 type Error struct { 28 Msg string 29 Code int 30 Err error 31 } 32 33 // Error implements error interface 34 func (e *Error) Error() string { 35 return fmt.Sprintf("msg:%s code:%v err:%v", e.Msg, e.Code, e.Err) 36 } 37 38 // Unwrap underlying error 39 func (e *Error) Unwrap() error { 40 return e.Err 41 } 42 43 func (e *Error) NotFound() bool { 44 return e.Code == StatusNotFound 45 } 46 47 func (e *Error) Forbidden() bool { 48 return e.Code == StatusForbidden 49 } 50 51 func (e *Error) BadRequest() bool { 52 return e.Code == StatusBadRequest 53 } 54 55 func (e *Error) UnprocessableEntity() bool { 56 return e.Code == StatusUnprocessableEntity 57 } 58 59 // ErrInvalidUserInput indicates a client-side error 60 type ErrInvalidUserInput struct { 61 msg string 62 } 63 64 func (e ErrInvalidUserInput) Error() string { 65 return e.msg 66 } 67 68 // NewErrInvalidUserInput with Errorf signature 69 func NewErrInvalidUserInput(format string, args ...interface{}) ErrInvalidUserInput { 70 return ErrInvalidUserInput{msg: fmt.Sprintf(format, args...)} 71 } 72 73 // ErrInternal indicates something went wrong during processing 74 type ErrInternal struct { 75 msg string 76 } 77 78 func (e ErrInternal) Error() string { 79 return e.msg 80 } 81 82 // NewErrInternal with Errorf signature 83 func NewErrInternal(format string, args ...interface{}) ErrInternal { 84 return ErrInternal{msg: fmt.Sprintf(format, args...)} 85 } 86 87 // ErrNotFound indicates the desired resource doesn't exist 88 type ErrNotFound struct { 89 msg string 90 } 91 92 func (e ErrNotFound) Error() string { 93 return e.msg 94 } 95 96 // NewErrNotFound with Errorf signature 97 func NewErrNotFound(format string, args ...interface{}) ErrNotFound { 98 return ErrNotFound{msg: fmt.Sprintf(format, args...)} 99 } 100 101 type ErrMultiTenancy struct { 102 err error 103 } 104 105 func (e ErrMultiTenancy) Error() string { 106 return e.err.Error() 107 } 108 109 // NewErrMultiTenancy with error signature 110 func NewErrMultiTenancy(err error) ErrMultiTenancy { 111 return ErrMultiTenancy{err} 112 }