mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-05-21 11:35:26 +00:00
fix: better error detail for failed sql
Some checks failed
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Failing after -35m9s
Build , Vet Test, and Lint / Build (push) Failing after -35m9s
Tests / Unit Tests (push) Failing after -35m10s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Failing after -35m9s
Build , Vet Test, and Lint / Lint Code (push) Failing after -35m9s
Tests / Integration Tests (push) Failing after -35m10s
Some checks failed
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Failing after -35m9s
Build , Vet Test, and Lint / Build (push) Failing after -35m9s
Tests / Unit Tests (push) Failing after -35m10s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Failing after -35m9s
Build , Vet Test, and Lint / Lint Code (push) Failing after -35m9s
Tests / Integration Tests (push) Failing after -35m10s
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
@@ -1757,18 +1758,21 @@ func (h *Handler) sendResponse(w common.ResponseWriter, data interface{}, metada
|
||||
}
|
||||
|
||||
func (h *Handler) sendError(w common.ResponseWriter, status int, code, message string, details interface{}) {
|
||||
apiErr := &common.APIError{
|
||||
Code: code,
|
||||
Message: message,
|
||||
Details: details,
|
||||
Detail: fmt.Sprintf("%v", details),
|
||||
}
|
||||
if asErr, ok := details.(error); ok {
|
||||
var sqlErr *common.SQLError
|
||||
if errors.As(asErr, &sqlErr) {
|
||||
apiErr.SQL = sqlErr.SQL
|
||||
}
|
||||
}
|
||||
w.SetHeader("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
err := w.WriteJSON(common.Response{
|
||||
Success: false,
|
||||
Error: &common.APIError{
|
||||
Code: code,
|
||||
Message: message,
|
||||
Details: details,
|
||||
Detail: fmt.Sprintf("%v", details),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
if err := w.WriteJSON(common.Response{Success: false, Error: apiErr}); err != nil {
|
||||
logger.Error("Error sending response: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user