mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 04:52:46 +00:00
Remove httputil.LogThenError so that the line numbers are reported properly - make error reporting slightly more useful (#879)
This commit is contained in:
parent
72565f2eeb
commit
59a1f4b8ed
37 changed files with 302 additions and 178 deletions
|
@ -19,7 +19,6 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/common/config"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
|
@ -72,12 +71,14 @@ func Backfill(
|
|||
ServerName: request.Origin(),
|
||||
}
|
||||
if req.Limit, err = strconv.Atoi(limit); err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("strconv.Atoi failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
// Query the roomserver.
|
||||
if err = query.QueryBackfill(httpReq.Context(), &req, &res); err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("query.QueryBackfill failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
// Filter any event that's not from the requested room out.
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/clientapi/userutil"
|
||||
"github.com/matrix-org/util"
|
||||
|
@ -43,7 +42,8 @@ func GetUserDevices(
|
|||
|
||||
devs, err := deviceDB.GetDevicesByLocalpart(req.Context(), localpart)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
util.GetLogger(req.Context()).WithError(err).Error("deviceDB.GetDevicesByLocalPart failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
return util.JSONResponse{
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/clientapi/producers"
|
||||
"github.com/matrix-org/dendrite/common/config"
|
||||
|
@ -78,7 +77,8 @@ func Invite(
|
|||
}}
|
||||
verifyResults, err := keys.VerifyJSONs(httpReq.Context(), verifyRequests)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("keys.VerifyJSONs failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
if verifyResults[0].Error != nil {
|
||||
return util.JSONResponse{
|
||||
|
@ -94,7 +94,8 @@ func Invite(
|
|||
|
||||
// Add the invite event to the roomserver.
|
||||
if err = producer.SendInvite(httpReq.Context(), signedEvent); err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendInvite failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
// Return the signed event to the originating server, it should then tell
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/clientapi/producers"
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
|
@ -60,7 +59,8 @@ func MakeJoin(
|
|||
}
|
||||
err = builder.SetContent(map[string]interface{}{"membership": gomatrixserverlib.Join})
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("builder.SetContent failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
var queryRes api.QueryLatestEventsAndStateResponse
|
||||
|
@ -71,7 +71,8 @@ func MakeJoin(
|
|||
JSON: jsonerror.NotFound("Room does not exist"),
|
||||
}
|
||||
} else if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("common.BuildEvent failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
// Check that the join is allowed or not
|
||||
|
@ -143,7 +144,8 @@ func SendJoin(
|
|||
}}
|
||||
verifyResults, err := keys.VerifyJSONs(httpReq.Context(), verifyRequests)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("keys.VerifyJSONs failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
if verifyResults[0].Error != nil {
|
||||
return util.JSONResponse{
|
||||
|
@ -161,7 +163,8 @@ func SendJoin(
|
|||
RoomID: roomID,
|
||||
}, &stateAndAuthChainResponse)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("query.QueryStateAndAuthChain failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
if !stateAndAuthChainResponse.RoomExists {
|
||||
|
@ -178,7 +181,8 @@ func SendJoin(
|
|||
httpReq.Context(), []gomatrixserverlib.Event{event}, cfg.Matrix.ServerName, nil,
|
||||
)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendEvents failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
return util.JSONResponse{
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/clientapi/producers"
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
|
@ -58,7 +57,8 @@ func MakeLeave(
|
|||
}
|
||||
err = builder.SetContent(map[string]interface{}{"membership": gomatrixserverlib.Leave})
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("builder.SetContent failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
var queryRes api.QueryLatestEventsAndStateResponse
|
||||
|
@ -69,7 +69,8 @@ func MakeLeave(
|
|||
JSON: jsonerror.NotFound("Room does not exist"),
|
||||
}
|
||||
} else if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("common.BuildEvent failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
// Check that the leave is allowed or not
|
||||
|
@ -140,7 +141,8 @@ func SendLeave(
|
|||
}}
|
||||
verifyResults, err := keys.VerifyJSONs(httpReq.Context(), verifyRequests)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("keys.VerifyJSONs failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
if verifyResults[0].Error != nil {
|
||||
return util.JSONResponse{
|
||||
|
@ -152,7 +154,8 @@ func SendLeave(
|
|||
// check membership is set to leave
|
||||
mem, err := event.Membership()
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("event.Membership failed")
|
||||
return jsonerror.InternalServerError()
|
||||
} else if mem != gomatrixserverlib.Leave {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
|
@ -165,7 +168,8 @@ func SendLeave(
|
|||
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
||||
_, err = producer.SendEvents(httpReq.Context(), []gomatrixserverlib.Event{event}, cfg.Matrix.ServerName, nil)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendEvents failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
return util.JSONResponse{
|
||||
|
|
|
@ -16,7 +16,6 @@ import (
|
|||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
@ -56,7 +55,8 @@ func GetMissingEvents(
|
|||
},
|
||||
&eventsResponse,
|
||||
); err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("query.QueryMissingEvents failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
eventsResponse.Events = filterEvents(eventsResponse.Events, gme.MinDepth, roomID)
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
|
||||
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
"github.com/matrix-org/dendrite/common/config"
|
||||
|
@ -46,16 +45,19 @@ func GetProfile(
|
|||
|
||||
_, domain, err := gomatrixserverlib.SplitID('@', userID)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("gomatrixserverlib.SplitID failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
if domain != cfg.Matrix.ServerName {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("domain != cfg.Matrix.ServerName failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
profile, err := appserviceAPI.RetrieveUserProfile(httpReq.Context(), userID, asAPI, accountDB)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("appserviceAPI.RetrieveUserProfile failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
var res interface{}
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/common/config"
|
||||
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
|
||||
|
@ -57,14 +56,16 @@ func RoomAliasToID(
|
|||
queryReq := roomserverAPI.GetRoomIDForAliasRequest{Alias: roomAlias}
|
||||
var queryRes roomserverAPI.GetRoomIDForAliasResponse
|
||||
if err = aliasAPI.GetRoomIDForAlias(httpReq.Context(), &queryReq, &queryRes); err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("aliasAPI.GetRoomIDForAlias failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
if queryRes.RoomID != "" {
|
||||
serverQueryReq := federationSenderAPI.QueryJoinedHostServerNamesInRoomRequest{RoomID: queryRes.RoomID}
|
||||
var serverQueryRes federationSenderAPI.QueryJoinedHostServerNamesInRoomResponse
|
||||
if err = senderAPI.QueryJoinedHostServerNamesInRoom(httpReq.Context(), &serverQueryReq, &serverQueryRes); err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("senderAPI.QueryJoinedHostServerNamesInRoom failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
resp = gomatrixserverlib.RespDirectory{
|
||||
|
@ -92,7 +93,8 @@ func RoomAliasToID(
|
|||
}
|
||||
// TODO: Return 502 if the remote server errored.
|
||||
// TODO: Return 504 if the remote server timed out.
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("federation.LookupRoomAlias failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/clientapi/producers"
|
||||
"github.com/matrix-org/dendrite/common/config"
|
||||
|
@ -61,7 +60,8 @@ func Send(
|
|||
|
||||
resp, err := t.processTransaction()
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("t.processTransaction failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
return util.JSONResponse{
|
||||
|
|
|
@ -74,7 +74,8 @@ func CreateInvitesFrom3PIDInvites(
|
|||
req.Context(), queryAPI, asAPI, cfg, inv, federation, accountDB,
|
||||
)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
util.GetLogger(req.Context()).WithError(err).Error("createInviteFrom3PIDInvite failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
if event != nil {
|
||||
evs = append(evs, *event)
|
||||
|
@ -83,7 +84,8 @@ func CreateInvitesFrom3PIDInvites(
|
|||
|
||||
// Send all the events
|
||||
if _, err := producer.SendEvents(req.Context(), evs, cfg.Matrix.ServerName, nil); err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
util.GetLogger(req.Context()).WithError(err).Error("producer.SendEvents failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
return util.JSONResponse{
|
||||
|
@ -143,21 +145,24 @@ func ExchangeThirdPartyInvite(
|
|||
JSON: jsonerror.NotFound("Unknown room " + roomID),
|
||||
}
|
||||
} else if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("buildMembershipEvent failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
// Ask the requesting server to sign the newly created event so we know it
|
||||
// acknowledged it
|
||||
signedEvent, err := federation.SendInvite(httpReq.Context(), request.Origin(), *event)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("federation.SendInvite failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
// Send the event to the roomserver
|
||||
if _, err = producer.SendEvents(
|
||||
httpReq.Context(), []gomatrixserverlib.Event{signedEvent.Event}, cfg.Matrix.ServerName, nil,
|
||||
); err != nil {
|
||||
return httputil.LogThenError(httpReq, err)
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendEvents failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
return util.JSONResponse{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue