[#4] native: Include error message in responses

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2022-05-20 12:22:11 +03:00 committed by Alex Vanin
parent 68999e49d4
commit 822c674c92
2 changed files with 18 additions and 8 deletions

View file

@ -18,5 +18,7 @@ export default function () {
let resp = neofs_cli.put(container, headers, payload) let resp = neofs_cli.put(container, headers, payload)
if (resp.success) { if (resp.success) {
neofs_cli.get(container, resp.object_id) neofs_cli.get(container, resp.object_id)
} else {
console.log(resp.error)
} }
} }

View file

@ -28,6 +28,12 @@ type (
PutResponse struct { PutResponse struct {
Success bool Success bool
ObjectID string ObjectID string
Error string
}
GetResponse struct {
Success bool
Error string
} }
) )
@ -78,14 +84,15 @@ func (c *Client) Put(inputContainerID string, headers map[string]string, payload
objectWriter, err := c.cli.ObjectPutInit(c.vu.Context(), client.PrmObjectPutInit{}) objectWriter, err := c.cli.ObjectPutInit(c.vu.Context(), client.PrmObjectPutInit{})
if err != nil { if err != nil {
stats.Report(c.vu, objPutFails, 1) stats.Report(c.vu, objPutFails, 1)
return PutResponse{Success: false} return PutResponse{Success: false, Error: err.Error()}
} }
objectWriter.WithinSession(tok) objectWriter.WithinSession(tok)
if !objectWriter.WriteHeader(o) { if !objectWriter.WriteHeader(o) {
stats.Report(c.vu, objPutFails, 1) stats.Report(c.vu, objPutFails, 1)
return PutResponse{Success: false} _, err := objectWriter.Close()
return PutResponse{Success: false, Error: err.Error()}
} }
n, _ := rdr.Read(buf) n, _ := rdr.Read(buf)
@ -99,7 +106,7 @@ func (c *Client) Put(inputContainerID string, headers map[string]string, payload
resp, err := objectWriter.Close() resp, err := objectWriter.Close()
if err != nil { if err != nil {
stats.Report(c.vu, objPutFails, 1) stats.Report(c.vu, objPutFails, 1)
return PutResponse{Success: false} return PutResponse{Success: false, Error: err.Error()}
} }
stats.ReportDataSent(c.vu, float64(sz)) stats.ReportDataSent(c.vu, float64(sz))
@ -111,7 +118,7 @@ func (c *Client) Put(inputContainerID string, headers map[string]string, payload
return PutResponse{Success: true, ObjectID: id.String()} return PutResponse{Success: true, ObjectID: id.String()}
} }
func (c *Client) Get(inputContainerID, inputObjectID string) bool { func (c *Client) Get(inputContainerID, inputObjectID string) GetResponse {
var ( var (
buf = make([]byte, 4*1024) buf = make([]byte, 4*1024)
sz int sz int
@ -152,13 +159,14 @@ func (c *Client) Get(inputContainerID, inputObjectID string) bool {
objectReader, err := c.cli.ObjectGetInit(c.vu.Context(), prmObjectGetInit) objectReader, err := c.cli.ObjectGetInit(c.vu.Context(), prmObjectGetInit)
if err != nil { if err != nil {
stats.Report(c.vu, objGetFails, 1) stats.Report(c.vu, objGetFails, 1)
return false return GetResponse{Success: false, Error: err.Error()}
} }
var o object.Object var o object.Object
if !objectReader.ReadHeader(&o) { if !objectReader.ReadHeader(&o) {
stats.Report(c.vu, objGetFails, 1) stats.Report(c.vu, objGetFails, 1)
return false _, err := objectReader.Close()
return GetResponse{Success: false, Error: err.Error()}
} }
n, _ := objectReader.Read(buf) n, _ := objectReader.Read(buf)
@ -170,10 +178,10 @@ func (c *Client) Get(inputContainerID, inputObjectID string) bool {
_, err = objectReader.Close() _, err = objectReader.Close()
if err != nil { if err != nil {
stats.Report(c.vu, objGetFails, 1) stats.Report(c.vu, objGetFails, 1)
return false return GetResponse{Success: false, Error: err.Error()}
} }
stats.Report(c.vu, objGetDuration, metrics.D(time.Since(start))) stats.Report(c.vu, objGetDuration, metrics.D(time.Since(start)))
stats.ReportDataReceived(c.vu, float64(sz)) stats.ReportDataReceived(c.vu, float64(sz))
return true return GetResponse{Success: true}
} }