diff options
Diffstat (limited to 'errors')
-rw-r--r-- | errors/errors.go | 47 | ||||
-rw-r--r-- | errors/status.go | 5 |
2 files changed, 30 insertions, 22 deletions
diff --git a/errors/errors.go b/errors/errors.go index 9fed3a3..c16bd52 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -23,35 +23,38 @@ import ( var ( // 204 - ErrEmptyResponse = errors.New("No Records Found") + ErrEmptyResponse = errors.New("No Records Found") // 400 - ErrNoWhereCondition = errors.New("No Where Condition") - ErrInvalidID = errors.New("Invalid ID") - ErrEmptyContactName = errors.New("Contact Name Cannot Be Empty") - ErrInvalidGSTIN = errors.New("Invalid GSTIN") - ErrInvalidEmail = errors.New("Invalid E-Mail Address") - ErrInvalidPhone = errors.New("Invalid Phone Number") - ErrInvalidWebsite = errors.New("Invalid Website URL") - ErrEmptyBrandName = errors.New("Brand Name Cannot Be Empty") - ErrInvalidUnitPrice = errors.New("Invalid Unit Price") - ErrInvalidGSTPercentage = errors.New("Invalid GST Percentage") - ErrPasswordTooShort = errors.New("Password Is Too Short") - ErrPasswordTooLong = errors.New("Password Is Too Long") - ErrInvalidLoginMethod = errors.New("Login Method Can Only Be 'email' Or 'username'") + ErrNoWhereCondition = errors.New("No Where Condition") + ErrInvalidID = errors.New("Invalid ID") + ErrEmptyContactName = errors.New("Contact Name Cannot Be Empty") + ErrInvalidGSTIN = errors.New("Invalid GSTIN") + ErrInvalidEmail = errors.New("Invalid E-Mail Address") + ErrInvalidPhone = errors.New("Invalid Phone Number") + ErrInvalidWebsite = errors.New("Invalid Website URL") + ErrEmptyBrandName = errors.New("Brand Name Cannot Be Empty") + ErrInvalidUnitPrice = errors.New("Invalid Unit Price") + ErrInvalidGSTPercentage = errors.New("Invalid GST Percentage") + ErrPasswordTooShort = errors.New("Password Is Too Short") + ErrPasswordTooLong = errors.New("Password Is Too Long") + ErrInvalidLoginMethod = errors.New("Login Method Can Only Be 'email' Or 'username'") // 401 - ErrWrongPassword = errors.New("Wrong Password") - ErrInvalidAuthHeader = errors.New("Invalid Authorization Header") - ErrUnauthorized = errors.New("Unauthorized") - ErrSessionExpired = errors.New("Session Expired") + ErrWrongPassword = errors.New("Wrong Password") + ErrInvalidAuthHeader = errors.New("Invalid Authorization Header") + ErrUnauthorized = errors.New("Unauthorized") + ErrSessionExpired = errors.New("Session Expired") // 403 - ErrForbidden = errors.New("You Are Not Authorized To Access This Resource") + ErrForbidden = errors.New("You Are Not Authorized To Access This Resource") // 404 - ErrNotFound = errors.New("Not Found") - ErrBrandNotFound = errors.New("This Brand Does Not Exist") + ErrNotFound = errors.New("Not Found") + ErrBrandNotFound = errors.New("This Brand Does Not Exist") + + // 405 + ErrCannotEditInvoice = errors.New("This Invoice Cannot Be Edited Now") // 409 ErrNonUniqueGSTIN = errors.New("GSTIN Must Be Unique") @@ -64,5 +67,5 @@ var ( ErrNonUniqueInvoiceNumber = errors.New("Invoice Number Must Be Unique") // 500 - ErrInternalServerError = errors.New("Internal Server Error") + ErrInternalServerError = errors.New("Internal Server Error") ) diff --git a/errors/status.go b/errors/status.go index c9113a9..47820b5 100644 --- a/errors/status.go +++ b/errors/status.go @@ -64,6 +64,11 @@ func StatusCodeFromErr(err error) int { return http.StatusNotFound } + // 405 + if errors.Is(err, ErrCannotEditInvoice) { + return http.StatusMethodNotAllowed + } + // 409 if errors.Is(err, ErrNonUniqueGSTIN) || errors.Is(err, ErrNonUniquePhone) || |