github.com/k0marov/go-socnet@v0.0.0-20220715154813-90d07867c782/core/general/client_errors/client_errors.go (about) 1 package client_errors 2 3 import "net/http" 4 5 type ClientError struct { 6 ReadableDetail string `json:"readable_detail"` 7 DetailCode string `json:"detail_code"` 8 HTTPCode int `json:"-"` 9 } 10 11 func (ce ClientError) Error() string { 12 return "An error which will be displayed to the client: " + ce.ReadableDetail 13 } 14 15 var InvalidJsonError = ClientError{ 16 DetailCode: "invalid-json", 17 ReadableDetail: "The provided request body is not valid JSON.", 18 HTTPCode: http.StatusBadRequest, 19 } 20 21 var AvatarNotProvidedError = ClientError{ 22 DetailCode: "no-avatar", 23 ReadableDetail: "You should provide an image in 'avatar' field.", 24 HTTPCode: http.StatusBadRequest, 25 } 26 27 var AvatarTooBigError = ClientError{ 28 DetailCode: "big-avatar", 29 ReadableDetail: "The avatar image you provided is too big.", 30 HTTPCode: http.StatusBadRequest, 31 } 32 33 var BodyIsNotMultipartForm = ClientError{ 34 DetailCode: "not-multipartform", 35 ReadableDetail: "Post data for this endpoint should be provided as a multipart form.", 36 HTTPCode: http.StatusBadRequest, 37 } 38 39 var NotFound = ClientError{ 40 DetailCode: "not-found", 41 ReadableDetail: "The requested entity was not found", 42 HTTPCode: http.StatusNotFound, 43 } 44 45 var AboutTooLong = ClientError{ 46 DetailCode: "about-long", 47 ReadableDetail: "The about field is too long", 48 HTTPCode: http.StatusBadRequest, 49 } 50 51 var InvalidImage = ClientError{ 52 DetailCode: "avatar-non-image", 53 ReadableDetail: "The provided image is not in one of supported image codecs.", 54 HTTPCode: http.StatusBadRequest, 55 } 56 57 var NonSquareAvatar = ClientError{ 58 DetailCode: "avatar-non-square", 59 ReadableDetail: "The provided avatar is a valid image, but it is not square.", 60 HTTPCode: http.StatusBadRequest, 61 } 62 63 var IdNotProvided = ClientError{ 64 DetailCode: "no-id", 65 ReadableDetail: "The request url was expected to have an 'id' query parameter, but there was none.", 66 HTTPCode: http.StatusBadRequest, 67 } 68 69 var FollowingYourself = ClientError{ 70 DetailCode: "following-yourself", 71 ReadableDetail: "You cannot follow yourself.", 72 HTTPCode: http.StatusBadRequest, 73 } 74 75 var InsufficientPermissions = ClientError{ 76 DetailCode: "insufficient-permissions", 77 ReadableDetail: "You are not authorized to perform this action.", 78 HTTPCode: http.StatusUnauthorized, 79 } 80 81 var LikingYourself = ClientError{ 82 DetailCode: "liking-yourself", 83 ReadableDetail: "You cannot like your own content", 84 HTTPCode: http.StatusBadRequest, 85 } 86 87 var TextTooLong = ClientError{ 88 DetailCode: "long-text", 89 ReadableDetail: "The provided text is too long.", 90 HTTPCode: http.StatusBadRequest, 91 } 92 93 var EmptyText = ClientError{ 94 DetailCode: "empty-text", 95 ReadableDetail: "Text cannot be empty.", 96 HTTPCode: http.StatusBadRequest, 97 } 98 99 var NonIntegerCount = ClientError{ 100 DetailCode: "non-integer-count", 101 ReadableDetail: "The \"count\" query argument of the feed endpoint should only be set to integers.", 102 HTTPCode: http.StatusBadRequest, 103 } 104 105 var TooBigCount = ClientError{ 106 DetailCode: "too-big-count", 107 ReadableDetail: "The provided count is too big.", 108 HTTPCode: http.StatusBadRequest, 109 }