Commit 14e71156 authored by Janos Guljas's avatar Janos Guljas

add logger to api server

parent b1eda29c
...@@ -24,6 +24,10 @@ type server struct { ...@@ -24,6 +24,10 @@ type server struct {
type Options struct { type Options struct {
Pingpong pingpong.Interface Pingpong pingpong.Interface
Logger interface {
Debugf(format string, args ...interface{})
Errorf(format string, args ...interface{})
}
} }
func New(o Options) Service { func New(o Options) Service {
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/pingpong" "github.com/ethersphere/bee/pkg/pingpong"
"resenje.org/web" "resenje.org/web"
) )
...@@ -27,11 +28,10 @@ type testServerOptions struct { ...@@ -27,11 +28,10 @@ type testServerOptions struct {
func newTestServer(t *testing.T, o testServerOptions) (client *http.Client, cleanup func()) { func newTestServer(t *testing.T, o testServerOptions) (client *http.Client, cleanup func()) {
s := New(Options{ s := New(Options{
Pingpong: o.Pingpong, Pingpong: o.Pingpong,
Logger: logging.New(ioutil.Discard),
}) })
ts := httptest.NewServer(s) ts := httptest.NewServer(s)
cleanup = func() { cleanup = ts.Close
ts.Close()
}
client = &http.Client{ client = &http.Client{
Transport: web.RoundTripperFunc(func(r *http.Request) (*http.Response, error) { Transport: web.RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
......
...@@ -25,9 +25,11 @@ func (s *server) pingpongHandler(w http.ResponseWriter, r *http.Request) { ...@@ -25,9 +25,11 @@ func (s *server) pingpongHandler(w http.ResponseWriter, r *http.Request) {
rtt, err := s.Pingpong.Ping(ctx, peerID, "hey", "there", ",", "how are", "you", "?") rtt, err := s.Pingpong.Ping(ctx, peerID, "hey", "there", ",", "how are", "you", "?")
if err != nil { if err != nil {
if errors.Is(err, p2p.ErrPeerNotFound) { if errors.Is(err, p2p.ErrPeerNotFound) {
s.Logger.Debugf("pingpong: ping %s: %w", peerID, err)
jsonhttp.NotFound(w, "peer not found") jsonhttp.NotFound(w, "peer not found")
return return
} }
s.Logger.Errorf("pingpong: ping %s: %w", peerID, err)
jsonhttp.InternalServerError(w, err.Error()) jsonhttp.InternalServerError(w, err.Error())
return return
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment