{"record":{"id":"0ace2f995dc9410c","repo":"transloadit/uppy","slug":"res-sendstatus-500-0ace2f","errorCode":null,"errorMessage":"res.sendStatus(500)","messagePattern":"res\\.sendStatus\\(500\\)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"packages/@uppy/companion/src/server/controllers/search.ts","lineNumber":19,"sourceCode":"import type { NextFunction, Request, Response } from 'express'\nimport { respondWithError } from '../provider/error.js'\n\nexport default async function search(\n  req: Request,\n  res: Response,\n  next: NextFunction,\n): Promise<void> {\n  const { query, companion } = req\n  const { providerUserSession, provider } = companion\n  if (!provider) {\n    res.sendStatus(400)\n    return\n  }\n\n  const buildURL = companion.buildURL\n  const q = query['q']\n  if (buildURL == null || typeof q !== 'string') {\n    res.sendStatus(500)\n    return\n  }\n\n  try {\n    const data = await provider.search({\n      companion: { buildURL },\n      providerUserSession,\n      query: { ...query, q },\n    })\n    res.json(data)\n  } catch (err) {\n    if (respondWithError(err, res)) return\n    next(err)\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/transloadit/uppy/blob/5d4dedd02a1ac0ae022c75c54aca76558f88e256/packages/@uppy/companion/src/server/controllers/search.ts#L1-L35","documentation":"The search controller returns HTTP 500 when companion.buildURL is missing or the 'q' query parameter is not a string. This is a server-side invariant failure: the URL builder was not injected or the query string was malformed/absent.","triggerScenarios":"Calling the search endpoint without a q parameter, with q duplicated into an array (?q=a&q=b), or when Companion's internal buildURL helper is not set on req.companion (miswired middleware/routing).","commonSituations":"Client sends GET to /search/:provider without a search term; custom middleware setup bypassing Companion's standard initializers; query parsers producing arrays for repeated params.","solutions":["Ensure the request includes a single string q parameter (normally guarded by hasSearchQuery middleware — check routing order)","Verify the provider search route uses the standard Companion router so req.companion.buildURL is attached","If q is user-supplied, validate/normalize it to a string before calling the endpoint"],"exampleFix":"// before\nfetch('/search/unsplash')\n// after\nfetch(`/search/unsplash?q=${encodeURIComponent(query)}`)","handlingStrategy":"type-guard","validationCode":"if (typeof q !== 'string' || q === '') throw new TypeError('q must be a non-empty string')","typeGuard":"const isSearchQuery = (q: unknown): q is string => typeof q === 'string' && q.length > 0","tryCatchPattern":null,"preventionTips":["Always use companion-client's provider.search() rather than raw fetch","Normalize query params before building URLs"],"tags":["companion","search","http-500","query-params"],"backgroundTag":"missing-query-parameter","analyzedSha":"5d4dedd02a1ac0ae022c75c54aca76558f88e256","analyzedAt":"2026-08-28T12:18:41.267Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}