mirror of https://github.com/fmartingr/bazaar.git
fix: handle shop not found properly, log more
This commit is contained in:
parent
9220b50e22
commit
0e560e07ac
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -30,6 +31,12 @@ func main() {
|
|||
|
||||
product, err := m.Retrieve(r.PostForm.Get("url"))
|
||||
if err != nil {
|
||||
if errors.Is(err, manager.ErrShopNotFound) {
|
||||
rw.WriteHeader(400)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("error for url %s: %s", r.PostForm.Get("url"), err)
|
||||
rw.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
"github.com/fmartingr/bazaar/pkg/models"
|
||||
)
|
||||
|
||||
var ErrShopNotFound = fmt.Errorf("shop not found for domain")
|
||||
|
||||
type Manager struct {
|
||||
domains map[string]models.Shop
|
||||
}
|
||||
|
@ -41,7 +43,7 @@ func (m *Manager) Retrieve(productURL string) (*models.Product, error) {
|
|||
|
||||
shop := m.GetShop(itemUrl.Host)
|
||||
if shop == nil {
|
||||
return nil, fmt.Errorf("shop not found for domain")
|
||||
return nil, ErrShopNotFound
|
||||
}
|
||||
|
||||
return shop.Get(productURL)
|
||||
|
|
Loading…
Reference in New Issue