aboutsummaryrefslogtreecommitdiff
path: root/http_server.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-10-30 13:50:15 +0700
committerShulhan <ms@kilabit.info>2023-10-30 14:08:19 +0700
commitacdada458cb1829cf5cc6aad6689440b65926165 (patch)
treea572ea0f3317afd85955c1e003b2741231909ca7 /http_server.go
parentf19fb2035877302e800cc2b1265b98f5e7ef28d1 (diff)
downloadawwan-acdada458cb1829cf5cc6aad6689440b65926165.tar.xz
all: return the error as reponse in HTTP API execute
Previously, when the command execution failed, we check the error and return it as HTTP status code 500. In this way, user cannot view the log and actual error. In this changes, if the command failed, we store the error in separate field "Error" and return to the caller with HTTP status code 200.
Diffstat (limited to 'http_server.go')
-rw-r--r--http_server.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/http_server.go b/http_server.go
index a50c0ec..4b667a4 100644
--- a/http_server.go
+++ b/http_server.go
@@ -396,8 +396,6 @@ func (httpd *httpServer) awwanApiExecute(epr *libhttp.EndpointRequest) (resb []b
logp = "awwanApiExecute"
req = &Request{}
res = &libhttp.EndpointResponse{}
-
- data *HttpResponse
)
res.Code = http.StatusInternalServerError
@@ -412,7 +410,13 @@ func (httpd *httpServer) awwanApiExecute(epr *libhttp.EndpointRequest) (resb []b
req.lineRange = parseLineRange(req.LineRange)
req.init()
- var logw bytes.Buffer
+ var (
+ data = &HttpResponse{
+ Request: req,
+ }
+
+ logw bytes.Buffer
+ )
req.registerLogWriter(`output`, &logw)
@@ -422,14 +426,10 @@ func (httpd *httpServer) awwanApiExecute(epr *libhttp.EndpointRequest) (resb []b
err = httpd.aww.Play(req)
}
if err != nil {
- res.Message = fmt.Sprintf("%s: %s", logp, err)
- return nil, res
+ data.Error = err.Error()
}
- data = &HttpResponse{
- Request: req,
- Output: logw.Bytes(),
- }
+ data.Output = logw.Bytes()
res.Code = http.StatusOK
res.Data = data