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

add logger to api server

parent b1eda29c
......@@ -24,6 +24,10 @@ type server struct {
type Options struct {
Pingpong pingpong.Interface
Logger interface {
Debugf(format string, args ...interface{})
Errorf(format string, args ...interface{})
}
}
func New(o Options) Service {
......
......@@ -14,6 +14,7 @@ import (
"strings"
"testing"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/pingpong"
"resenje.org/web"
)
......@@ -27,11 +28,10 @@ type testServerOptions struct {
func newTestServer(t *testing.T, o testServerOptions) (client *http.Client, cleanup func()) {
s := New(Options{
Pingpong: o.Pingpong,
Logger: logging.New(ioutil.Discard),
})
ts := httptest.NewServer(s)
cleanup = func() {
ts.Close()
}
cleanup = ts.Close
client = &http.Client{
Transport: web.RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
......
......@@ -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", "?")
if err != nil {
if errors.Is(err, p2p.ErrPeerNotFound) {
s.Logger.Debugf("pingpong: ping %s: %w", peerID, err)
jsonhttp.NotFound(w, "peer not found")
return
}
s.Logger.Errorf("pingpong: ping %s: %w", peerID, err)
jsonhttp.InternalServerError(w, err.Error())
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