Skip to content
Snippets Groups Projects
Commit b209ab4e authored by meskio's avatar meskio :tent:
Browse files

User 'errors.Is' instead of parsing the error message

parent 3e8f0d81
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ package api
import (
"encoding/json"
"errors"
"log"
"net/http"
"strconv"
......@@ -90,7 +91,7 @@ func (a *api) getMemberNum(num int, w http.ResponseWriter, req *http.Request) {
var member Member
err := a.db.Where("num = ?", num).First(&member).Error
if err != nil {
if err.Error() == "record not found" {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.WriteHeader(http.StatusNotFound)
return
}
......@@ -132,7 +133,7 @@ func (a *api) UpdateMember(w http.ResponseWriter, req *http.Request) {
var dbMember Member
err = a.db.Where("num = ?", vars["num"]).First(&dbMember).Error
if err != nil {
if err.Error() == "record not found" {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.WriteHeader(http.StatusNotFound)
return
}
......
......@@ -2,6 +2,7 @@ package api
import (
"encoding/json"
"errors"
"log"
"net/http"
"time"
......@@ -130,7 +131,7 @@ func (a *api) GetOrder(num int, w http.ResponseWriter, req *http.Request) {
err := a.db.Preload(clause.Associations).
First(&order, vars["id"]).Error
if err != nil {
if err.Error() == "record not found" {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.WriteHeader(http.StatusNotFound)
return
}
......
......@@ -2,6 +2,7 @@ package api
import (
"encoding/json"
"errors"
"log"
"net/http"
......@@ -65,7 +66,7 @@ func (a *api) GetProduct(w http.ResponseWriter, req *http.Request) {
var product Product
err := a.db.Where("code = ?", vars["code"]).First(&product).Error
if err != nil {
if err.Error() == "record not found" {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.WriteHeader(http.StatusNotFound)
return
}
......@@ -107,7 +108,7 @@ func (a *api) UpdateProduct(w http.ResponseWriter, req *http.Request) {
var dbProduct Product
err = a.db.Where("code = ?", vars["code"]).First(&dbProduct).Error
if err != nil {
if err.Error() == "record not found" {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.WriteHeader(http.StatusNotFound)
return
}
......
......@@ -2,6 +2,7 @@ package api
import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
......@@ -54,7 +55,7 @@ func (a *api) GetTransaction(num int, role string, w http.ResponseWriter, req *h
Preload(clause.Associations).
First(&transaction, vars["id"]).Error
if err != nil {
if err.Error() == "record not found" {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.WriteHeader(http.StatusNotFound)
return
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment