Add JSON parse error handling with debug output
This commit is contained in:
parent
ec59f05814
commit
89adfbc92e
1 changed files with 18 additions and 1 deletions
|
|
@ -350,9 +350,26 @@
|
|||
<cfset responseText = left(responseText, len(responseText) - 3)>
|
||||
</cfif>
|
||||
<cfset responseText = trim(responseText)>
|
||||
<!--- Remove trailing commas before ] or } --->
|
||||
<cfset responseText = reReplace(responseText, ",(\s*[\]\}])", "\1", "all")>
|
||||
<!--- Remove control characters that break JSON --->
|
||||
<cfset responseText = reReplace(responseText, "[\x00-\x1F]", " ", "all")>
|
||||
|
||||
<cfset menuData = deserializeJSON(responseText)>
|
||||
<!--- Try to parse JSON with error handling --->
|
||||
<cftry>
|
||||
<cfset menuData = deserializeJSON(responseText)>
|
||||
<cfcatch type="any">
|
||||
<!--- JSON parsing failed - try to extract what we can --->
|
||||
<!--- Return the raw response for debugging --->
|
||||
<cfset response["success"] = false>
|
||||
<cfset response["error"] = "JSON parse error: #cfcatch.message#">
|
||||
<cfset response["DEBUG_RAW_RESPONSE"] = left(responseText, 2000)>
|
||||
<cfset response["DEBUG_RESPONSE_LENGTH"] = len(responseText)>
|
||||
<cfcontent type="application/json" reset="true">
|
||||
<cfoutput>#serializeJSON(response)#</cfoutput>
|
||||
<cfabort>
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
|
||||
<!--- Debug: save raw Claude response before processing --->
|
||||
<cfset response["DEBUG_RAW_CLAUDE"] = responseText>
|
||||
|
|
|
|||
Reference in a new issue