| 489 | } |
| 490 | |
| 491 | func wrapSearchConsoleError(err error) error { |
| 492 | var apiErr *gapi.Error |
| 493 | if !errors.As(err, &apiErr) { |
| 494 | return err |
| 495 | } |
| 496 | if apiErr.Code != 403 { |
| 497 | return err |
| 498 | } |
| 499 | |
| 500 | message := strings.ToLower(apiErr.Message) |
| 501 | switch { |
| 502 | case strings.Contains(message, "accessnotconfigured"), strings.Contains(message, "api has not been used"): |
| 503 | return fmt.Errorf("search console API is not enabled for this OAuth project. Enable it at https://console.cloud.google.com/apis/api/searchconsole.googleapis.com") |
| 504 | case strings.Contains(message, "insufficientpermissions"), strings.Contains(message, "insufficient permission"): |
| 505 | return fmt.Errorf("insufficient permissions for Search Console API. Re-authorize with: gog auth add <email> --services searchconsole") |
| 506 | default: |
| 507 | return err |
| 508 | } |
| 509 | } |