MCPcopy
hub / github.com/codeaashu/claude-code / getErrorMessageIfRefusal

Function getErrorMessageIfRefusal

src/services/api/errors.ts:1184–1207  ·  view source on GitHub ↗
(
  stopReason: BetaStopReason | null,
  model: string,
)

Source from the content-addressed store, hash-verified

1182}
1183
1184export function getErrorMessageIfRefusal(
1185 stopReason: BetaStopReason | null,
1186 model: string,
1187): AssistantMessage | undefined {
1188 if (stopReason !== 'refusal') {
1189 return
1190 }
1191
1192 logEvent('tengu_refusal_api_response', {})
1193
1194 const baseMessage = getIsNonInteractiveSession()
1195 ? `${API_ERROR_MESSAGE_PREFIX}: Claude Code is unable to respond to this request, which appears to violate our Usage Policy (https://www.anthropic.com/legal/aup). Try rephrasing the request or attempting a different approach.`
1196 : `${API_ERROR_MESSAGE_PREFIX}: Claude Code is unable to respond to this request, which appears to violate our Usage Policy (https://www.anthropic.com/legal/aup). Please double press esc to edit your last message or start a new session for Claude Code to assist with a different task.`
1197
1198 const modelSuggestion =
1199 model !== 'claude-sonnet-4-20250514'
1200 ? ' If you are seeing this refusal repeatedly, try running /model claude-sonnet-4-20250514 to switch models.'
1201 : ''
1202
1203 return createAssistantAPIErrorMessage({
1204 content: baseMessage + modelSuggestion,
1205 error: 'invalid_request',
1206 })
1207}
1208

Callers 1

queryModelFunction · 0.85

Calls 3

logEventFunction · 0.85

Tested by

no test coverage detected