translateMetadataError maps GetDatabaseMetadata HTTP errors into toolError codes.
(resp *apiResponse)
| 414 | |
| 415 | // translateMetadataError maps GetDatabaseMetadata HTTP errors into toolError codes. |
| 416 | func translateMetadataError(resp *apiResponse) error { |
| 417 | errMsg := parseError(resp.Body) |
| 418 | switch resp.Status { |
| 419 | case http.StatusNotFound: |
| 420 | return &toolError{ |
| 421 | Code: "DATABASE_NOT_FOUND", |
| 422 | Message: "database not found", |
| 423 | Suggestion: "check the database name or use search_api to list available databases", |
| 424 | } |
| 425 | case http.StatusForbidden, http.StatusUnauthorized: |
| 426 | return &toolError{ |
| 427 | Code: "PERMISSION_DENIED", |
| 428 | Message: "you don't have permission to read this database's schema", |
| 429 | Suggestion: "ask your workspace admin to grant you the bb.databases.getSchema permission", |
| 430 | } |
| 431 | case http.StatusInternalServerError: |
| 432 | suggestion := "check instance connectivity in the Bytebase UI" |
| 433 | if errMsg != "" { |
| 434 | suggestion = fmt.Sprintf("%s; backend error: %s", suggestion, errMsg) |
| 435 | } |
| 436 | return &toolError{ |
| 437 | Code: "SCHEMA_SYNC_FAILED", |
| 438 | Message: "the database is reachable but the schema sync failed", |
| 439 | Suggestion: suggestion, |
| 440 | } |
| 441 | default: |
| 442 | if errMsg == "" { |
| 443 | errMsg = fmt.Sprintf("HTTP %d", resp.Status) |
| 444 | } |
| 445 | return &toolError{ |
| 446 | Code: "SCHEMA_FETCH_ERROR", |
| 447 | Message: errMsg, |
| 448 | Suggestion: "check the database name and try again", |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | // tableMatch holds a single (schema, table) match found during lookup. |
| 454 | type tableMatch struct { |
no test coverage detected