[#18] Extract error details

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2023-03-13 14:55:19 +03:00
parent e02ee50d7b
commit 8f6be59e23
4 changed files with 50 additions and 12 deletions

View file

@ -182,8 +182,7 @@ func (u *Uploader) Upload(c *fasthttp.RequestCtx) {
}
if idObj, err = u.pool.PutObject(u.appCtx, prm); err != nil {
log.Error("could not store file in frostfs", zap.Error(err))
response.Error(c, "could not store file in frostfs: "+err.Error(), fasthttp.StatusBadRequest)
u.handlePutFrostFSErr(c, err)
return
}
@ -214,6 +213,14 @@ func (u *Uploader) Upload(c *fasthttp.RequestCtx) {
c.Response.Header.SetContentType(jsonHeader)
}
func (u *Uploader) handlePutFrostFSErr(r *fasthttp.RequestCtx, err error) {
statusCode, msg, additionalFields := response.FormErrorResponse("could not store file in frostfs", err)
logFields := append([]zap.Field{zap.Error(err)}, additionalFields...)
u.log.Error("could not store file in frostfs", logFields...)
response.Error(r, msg, statusCode)
}
func (u *Uploader) fetchOwnerAndBearerToken(ctx context.Context) (*user.ID, *bearer.Token) {
if tkn, err := tokens.LoadBearerToken(ctx); err == nil && tkn != nil {
issuer := bearer.ResolveIssuer(*tkn)