{"record":{"id":"985cb3f0390e2386","repo":"owasp-amass/amass","slug":"bad-request","errorCode":null,"errorMessage":"bad request","messagePattern":"bad request","errorType":"http","errorClass":"ErrBadRequest","httpStatus":400,"severity":"error","filePath":"engine/api/server/v1/handlers.go","lineNumber":63,"sourceCode":"type AddAssetResponse struct {\n\tEntityID string `json:\"entityID\"`\n}\n\n// Bulk typed add: {\"items\":[ <OAM obj>, <OAM obj>, ... ]}\n// where each item is arbitrary JSON object without \"type\".\ntype BulkAddAssetsRequest struct {\n\tItems []json.RawMessage `json:\"items\"`\n}\n\ntype BulkAddAssetsResponse struct {\n\tIngested int64 `json:\"ingested\"`\n\tStored   int64 `json:\"stored\"`\n\tFailed   int64 `json:\"failed\"`\n}\n\nvar (\n\tErrNotFound   = errors.New(\"not found\")\n\tErrBadRequest = errors.New(\"bad request\")\n)\n\ntype V1Handlers struct {\n\tctx context.Context\n\tlog *slog.Logger\n\tdis et.Dispatcher\n\tmgr et.SessionManager\n}\n\nfunc NewV1Handlers(ctx context.Context, dis et.Dispatcher, mgr et.SessionManager, log *slog.Logger) (*V1Handlers, error) {\n\treturn &V1Handlers{\n\t\tctx: ctx,\n\t\tlog: log,\n\t\tdis: dis,\n\t\tmgr: mgr,\n\t}, nil\n}\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/engine/api/server/v1/handlers.go#L45-L81","documentation":"ErrBadRequest is the sentinel returned when the request body cannot be used. readRawJSON returns it when the raw JSON body is empty, signaling HTTP 400 to API callers that a non-empty JSON body is required.","triggerScenarios":"Calling a v1 endpoint that reads a JSON body (via readRawJSON) with an empty body — e.g. POST/PUT without a payload, or a client that serializes nothing — making len(raw) == 0.","commonSituations":"Testing the API with curl without -d '{...}', an HTTP client sending no body on ingest endpoints like AddAssetTyped/AddAssetsBulk, or Content-Length 0 due to client serialization bugs.","solutions":["Send a non-empty JSON body with the correct Content-Type: application/json.","Inspect the client code to ensure the payload is actually serialized and attached.","Handle HTTP 400 client-side and retry with a valid payload.","Check for early-terminated writes or streaming failures in the client."],"exampleFix":"# before\ncurl -X POST http://host/v1/assets/typed\n# after\ncurl -X POST http://host/v1/assets/typed -H 'Content-Type: application/json' -d '{\"scope\":\"example.com\",\"asset\":\"a.example.com\"}'","handlingStrategy":"validation","validationCode":"payload, err := json.Marshal(body)\nif err != nil { return err }\nif len(payload) == 0 { return errors.New(\"request body must be non-empty JSON\") }","typeGuard":null,"tryCatchPattern":"resp, err := client.Do(req)\nif err != nil { return err }\nif resp.StatusCode == http.StatusBadRequest {\n    return fmt.Errorf(\"request rejected (bad request): check JSON body is non-empty and valid\")\n}","preventionTips":["Always attach a serialized JSON body to POST/PUT requests.","Set Content-Type: application/json on the client.","Smoke-test endpoints with curl including -d payloads.","Log outgoing request body sizes in debug mode."],"tags":["api","http","bad-request"],"backgroundTag":"empty-response-body","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}