mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-05-21 19:45:33 +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"
|
||||
@@ -579,8 +580,8 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
|
||||
// preload LEFT JOIN (to prevent "table name specified more than once" errors).
|
||||
if len(options.CustomSQLJoin) > 0 {
|
||||
preloadAliasSet := make(map[string]bool, len(options.Preload))
|
||||
for _, p := range options.Preload {
|
||||
if alias := common.RelationPathToBunAlias(p.Relation); alias != "" {
|
||||
for i := range options.Preload {
|
||||
if alias := common.RelationPathToBunAlias(options.Preload[i].Relation); alias != "" {
|
||||
preloadAliasSet[alias] = true
|
||||
}
|
||||
}
|
||||
@@ -2645,6 +2646,12 @@ func (h *Handler) sendError(w common.ResponseWriter, statusCode int, code, messa
|
||||
"_error": errorMsg,
|
||||
"_retval": 1,
|
||||
}
|
||||
|
||||
var sqlErr *common.SQLError
|
||||
if errors.As(err, &sqlErr) {
|
||||
response["_sql"] = sqlErr.SQL
|
||||
}
|
||||
|
||||
w.SetHeader("Content-Type", "application/json")
|
||||
w.WriteHeader(statusCode)
|
||||
if jsonErr := w.WriteJSON(response); jsonErr != nil {
|
||||
|
||||
Reference in New Issue
Block a user