Skip to content
Snippets Groups Projects
Commit 020be607 authored by Travis Ralston's avatar Travis Ralston
Browse files

Light code cleanup

parent b9ffed61
No related branches found
No related tags found
No related merge requests found
File moved
......@@ -35,20 +35,20 @@ type RequestContext struct {
context.Context
// These are also stored on the context object itself
Log *logrus.Entry // mr.logger
Config config.DomainRepoConfig // mr.serverConfig
Request *http.Request // mr.request
Log *logrus.Entry // mmr.logger
Config config.DomainRepoConfig // mmr.serverConfig
Request *http.Request // mmr.request
}
func (c RequestContext) populate() RequestContext {
c.Context = context.WithValue(c.Context, "mr.logger", c.Log)
c.Context = context.WithValue(c.Context, "mr.serverConfig", c.Config)
c.Context = context.WithValue(c.Context, "mr.request", c.Request)
c.Context = context.WithValue(c.Context, "mmr.logger", c.Log)
c.Context = context.WithValue(c.Context, "mmr.serverConfig", c.Config)
c.Context = context.WithValue(c.Context, "mmr.request", c.Request)
return c
}
func (c RequestContext) ReplaceLogger(log *logrus.Entry) RequestContext {
ctx := context.WithValue(c.Context, "mr.logger", log)
ctx := context.WithValue(c.Context, "mmr.logger", log)
return RequestContext{
Context: ctx,
Log: log,
......
......@@ -8,6 +8,16 @@ import (
const selectLocalMedia = "SELECT media_id, media_type, media_length, created_ts, upload_name, user_id, url_cache FROM local_media_repository;"
type LocalMedia struct {
MediaId string
ContentType string
SizeBytes int64
CreatedTs int64
UploadName string
UserId string
UrlCache string
}
type SynDatabase struct {
db *sql.DB
statements statements
......
package synapse
type LocalMedia struct {
MediaId string
ContentType string
SizeBytes int64
CreatedTs int64
UploadName string
UserId string
UrlCache string
}
......@@ -35,7 +35,7 @@ func doBreakerRequest(ctx rcontext.RequestContext, serverName string, accessToke
target.RawQuery = q.Encode()
err := doRequest(ctx, method, target.String(), nil, resp, accessToken, ipAddr)
if err != nil {
ctx.Log.Warn("Error from homeserver: ", err)
ctx.Log.Debug("Error from homeserver: ", err)
err, authError = filterError(err)
return err
}
......
......@@ -8,13 +8,12 @@ import (
"net/http"
"time"
"github.com/sirupsen/logrus"
"github.com/turt2live/matrix-media-repo/common/rcontext"
)
// Based in part on https://github.com/matrix-org/gomatrix/blob/072b39f7fa6b40257b4eead8c958d71985c28bdd/client.go#L180-L243
func doRequest(ctx rcontext.RequestContext, method string, urlStr string, body interface{}, result interface{}, accessToken string, ipAddr string) error {
logrus.Infof("Calling %s %s", method, urlStr)
ctx.Log.Debugf("Calling %s %s", method, urlStr)
var bodyBytes []byte
if body != nil {
jsonStr, err := json.Marshal(body)
......
package matrix
import (
"errors"
"sync"
"github.com/rubyist/circuitbreaker"
......@@ -35,7 +36,8 @@ func filterError(err error) (error, error) {
}
// Unknown token errors should be filtered out explicitly to ensure we don't break on bad requests
if httpErr, ok := err.(*errorResponse); ok {
var httpErr *errorResponse
if errors.As(err, &httpErr) {
// We send back our own version of errors to ensure we can filter them out elsewhere
if httpErr.ErrorCode == common.ErrCodeUnknownToken {
return nil, ErrInvalidToken
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment