{"record":{"id":"ac960cdf2e8e2578","repo":"owasp-amass/amass","slug":"createasset-status-s-error-s","errorCode":null,"errorMessage":"createAsset: status=%s error=%s","messagePattern":"createAsset: status=(.+?) error=(.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/api/client/v1/client.go","lineNumber":240,"sourceCode":"\n\tsessionID := token.String()\n\tu := fmt.Sprintf(\"%s/sessions/%s/assets/%s\", c.base, sessionID, atype)\n\tresp, err := amasshttp.RequestWebPage(ctx, c.httpClient, &amasshttp.Request{\n\t\tURL:    u,\n\t\tBody:   string(raw),\n\t\tMethod: http.MethodPost,\n\t\tHeader: amasshttp.Header{\"Content-Type\": []string{\"application/json\"}},\n\t})\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tmsg, err := readJSONError(resp.Body)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"createAsset: status=%s\", resp.Status)\n\t\t}\n\t\treturn \"\", fmt.Errorf(\"createAsset: status=%s error=%s\", resp.Status, msg)\n\t}\n\n\tvar r AddAssetResponse\n\tif err := json.Unmarshal([]byte(resp.Body), &r); err != nil {\n\t\treturn \"\", err\n\t}\n\treturn r.EntityID, nil\n}\n\n// Creates multiple assets in bulk on the server associated with the provided token.\nfunc (c *Client) CreateAssetsBulk(ctx context.Context, token uuid.UUID, atype string, assets []oam.Asset) (int, error) {\n\tatype = strings.ToLower(strings.TrimSpace(atype))\n\n\tif atype == \"\" {\n\t\treturn 0, fmt.Errorf(\"CreateAssetsBulk: asset type required\")\n\t}\n\tif len(assets) > MaxBulkItems {\n\t\treturn 0, fmt.Errorf(\"CreateAssetsBulk: too many items; max=%d\", MaxBulkItems)","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/engine/api/client/v1/client.go#L222-L258","documentation":"CreateAsset's informative variant: the server returned non-200 and its JSON error body parsed successfully, so the client surfaces the server's own error message alongside the HTTP status. The asset was not created.","triggerScenarios":"Calling Client.CreateAsset when the server rejects the asset — invalid session token (401), unknown asset type path (404), failed validation/storage (400/500) — with a well-formed JSON error body.","commonSituations":"Posting an asset whose fields fail server-side validation, using a token after session teardown, or a type mismatch between the asset and the URL segment.","solutions":["Read the error=%s message: it is the server's explanation of the rejection.","Ensure asset.AssetType() matches the endpoint type segment derived from it (client derives it automatically — verify the concrete asset type is supported).","Re-validate required asset fields before sending.","Re-authenticate if the server reported an auth failure.","Retry on transient 5xx statuses."],"exampleFix":"// before\n_, err := client.CreateAsset(ctx, token, asset)\n// after\n_, err := client.CreateAsset(ctx, token, asset)\nif err != nil && strings.Contains(err.Error(), \"status=409\") {\n    // asset already exists; treat as success or deduplicate first\n}","handlingStrategy":"try-catch","validationCode":"if token == uuid.Nil { return errors.New(\"session token not initialized\") }\nif _, err := asset.JSON(); err != nil { return err }","typeGuard":"func isServerError(err error) bool { return err != nil && strings.Contains(err.Error(), \"status=5\") }","tryCatchPattern":"id, err := client.CreateAsset(ctx, token, asset)\nif err != nil {\n    switch {\n    case strings.Contains(err.Error(), \"status=401\"): token = reauth(ctx)\n    case strings.Contains(err.Error(), \"status=409\"): /* dedupe */\n    default: return err\n    }\n}","preventionTips":["Log the server-provided error message for diagnosis.","Match the asset's concrete type to a server-supported oam.AssetType.","Deduplicate assets client-side to avoid 409s.","Refresh session tokens proactively."],"tags":["http","api-client","server-error"],"backgroundTag":"http-error-response","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}