diff --git a/coap/api/transport.go b/coap/api/transport.go index 417c24255fc..d40b51f7493 100644 --- a/coap/api/transport.go +++ b/coap/api/transport.go @@ -93,12 +93,14 @@ func handler(w mux.ResponseWriter, m *mux.Message) { if err != nil { logger.Warn(fmt.Sprintf("Error decoding message: %s", err)) resp.Code = codes.BadRequest + sendResp(w, &resp, false) return } key, err := parseKey(m) if err != nil { logger.Warn(fmt.Sprintf("Error parsing auth: %s", err)) resp.Code = codes.Unauthorized + sendResp(w, &resp, false) return } var isObs bool = false @@ -107,7 +109,7 @@ func handler(w mux.ResponseWriter, m *mux.Message) { isObs, err = handleGet(context.Background(), m, w, msg, key) case codes.POST: resp.Code = codes.Created - err = nil + err = service.Publish(m.Context(), key, msg) default: err = svcerr.ErrNotFound } diff --git a/coap/client.go b/coap/client.go index ea8a52e17a4..08a26f36f8f 100644 --- a/coap/client.go +++ b/coap/client.go @@ -102,5 +102,8 @@ func (c *client) Handle(msg *messaging.Message) error { for _, option := range opts { pm.SetOptionBytes(option.ID, option.Value) } - return c.client.Conn().WriteMessage(pm) + if err = c.client.Conn().WriteMessage(pm); err != nil { + return err + } + return nil }