summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-09-17 19:12:12 +0200
committerLibravatar GitHub <noreply@github.com>2022-09-17 19:12:12 +0200
commitc1585d5f8a57256a330aae4a322468aaccf9d3fa (patch)
treef31dec55572d068f1bee8615f5ccda7454d762f9 /internal
parent[bugfix] Fix emojis, attachments, and mentions not being serialized correctly... (diff)
downloadgotosocial-c1585d5f8a57256a330aae4a322468aaccf9d3fa.tar.xz
[bugfix] Fix domains not being unblockable, log internal server errors from API (#833)
* log internal server errors from 500 api calls * don't exec into nil dest * don't exec into nil dest * log error in router logger not api errorhandling * update logging a tad * linter
Diffstat (limited to 'internal')
-rw-r--r--internal/api/errorhandling.go4
-rw-r--r--internal/db/bundb/domain.go2
-rw-r--r--internal/router/logger.go16
3 files changed, 9 insertions, 13 deletions
diff --git a/internal/api/errorhandling.go b/internal/api/errorhandling.go
index 346841f3f..f6fec4168 100644
--- a/internal/api/errorhandling.go
+++ b/internal/api/errorhandling.go
@@ -86,6 +86,10 @@ func genericErrorHandler(c *gin.Context, instanceGet func(ctx context.Context, d
// if something goes wrong during the function, it will recover and just try to serve
// an appropriate application/json content-type error.
func ErrorHandler(c *gin.Context, errWithCode gtserror.WithCode, instanceGet func(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode)) {
+ // set the error on the gin context so that it can be logged
+ // in the gin logger middleware (internal/router/logger.go)
+ c.Error(errWithCode) //nolint:errcheck
+
// discover if we're allowed to serve a nice html error page,
// or if we should just use a json. Normally we would want to
// check for a returned error, but if an error occurs here we
diff --git a/internal/db/bundb/domain.go b/internal/db/bundb/domain.go
index 4cad75e4d..0d67837d7 100644
--- a/internal/db/bundb/domain.go
+++ b/internal/db/bundb/domain.go
@@ -107,7 +107,7 @@ func (d *domainDB) DeleteDomainBlock(ctx context.Context, domain string) db.Erro
_, err := d.conn.NewDelete().
Model((*gtsmodel.DomainBlock)(nil)).
Where("domain = ?", domain).
- Exec(ctx, nil)
+ Exec(ctx)
if err != nil {
return d.conn.ProcessError(err)
}
diff --git a/internal/router/logger.go b/internal/router/logger.go
index 2e23b9cfb..6eb271a84 100644
--- a/internal/router/logger.go
+++ b/internal/router/logger.go
@@ -72,29 +72,21 @@ func loggingMiddleware(c *gin.Context) {
fields[4] = kv.Field{"statusCode", code}
fields[5] = kv.Field{"path", path}
- var lvl level.LEVEL
+ // Create log entry with fields
+ l := log.WithFields(fields...)
// Default is info
- lvl = level.INFO
+ lvl := level.INFO
if code >= 500 {
// This is a server error
lvl = level.ERROR
-
- if len(c.Errors) > 0 {
- // Add an error string log field
- fields = append(fields, kv.Field{
- "error", c.Errors.String(),
- })
- }
+ l = l.WithField("error", c.Errors)
}
// Generate a nicer looking bytecount
size := bytesize.Size(c.Writer.Size())
- // Create log entry with fields
- l := log.WithFields(fields...)
-
// Finally, write log entry with status text body size
l.Logf(lvl, "%s: wrote %s", http.StatusText(code), size)
}()