wrapCollectionNotFound rewrites the server's context-free "Collection not found" into one that names the slug the user actually typed, so a failed `pad item create widget …` reads `collection "widget" not found` instead of a bare "Collection not found". It returns a fresh *APIError with the same Cod
(err error, rawSlug string)
| 109 | // working) and an enriched Message. Non-collection errors pass through |
| 110 | // untouched. Mirrors wrapItemNotFound's shape. |
| 111 | func wrapCollectionNotFound(err error, rawSlug string) error { |
| 112 | var apiErr *APIError |
| 113 | if errors.As(err, &apiErr) && isCollectionNotFound(err) { |
| 114 | return &APIError{ |
| 115 | Code: apiErr.Code, |
| 116 | Message: fmt.Sprintf("collection %q not found", rawSlug), |
| 117 | Details: apiErr.Details, |
| 118 | } |
| 119 | } |
| 120 | return err |
| 121 | } |
| 122 | |
| 123 | // isCollectionNotFound reports whether err is the server's specific |
| 124 | // "collection not found" response for an item create / list / move request. It |
no test coverage detected