MCPcopy Create free account
hub / github.com/codeaashu/claude-code / parseHttpHookOutput

Function parseHttpHookOutput

src/utils/hooks.ts:453–487  ·  view source on GitHub ↗
(body: string)

Source from the content-addressed store, hash-verified

451}
452
453function parseHttpHookOutput(body: string): {
454 json?: HookJSONOutput
455 validationError?: string
456} {
457 const trimmed = body.trim()
458
459 if (trimmed === '') {
460 const validation = hookJSONOutputSchema().safeParse({})
461 if (validation.success) {
462 logForDebugging(
463 'HTTP hook returned empty body, treating as empty JSON object',
464 )
465 return { json: validation.data }
466 }
467 }
468
469 if (!trimmed.startsWith('{')) {
470 const validationError = `HTTP hook must return JSON, but got non-JSON response body: ${trimmed.length > 200 ? trimmed.slice(0, 200) + '\u2026' : trimmed}`
471 logForDebugging(validationError)
472 return { validationError }
473 }
474
475 try {
476 const result = validateHookJson(trimmed)
477 if ('json' in result) {
478 return result
479 }
480 logForDebugging(result.validationError)
481 return result
482 } catch (e) {
483 const validationError = `HTTP hook must return valid JSON, but parsing failed: ${e}`
484 logForDebugging(validationError)
485 return { validationError }
486 }
487}
488
489function processHookJSONOutput({
490 json,

Callers 2

executeHooksFunction · 0.85
executeHooksOutsideREPLFunction · 0.85

Calls 2

logForDebuggingFunction · 0.85
validateHookJsonFunction · 0.85

Tested by

no test coverage detected