Raise appropriate exception based on error code in response.
(self, response_json)
| 84 | raise error |
| 85 | |
| 86 | def _raise_for_error_code(self, response_json): |
| 87 | """Raise appropriate exception based on error code in response.""" |
| 88 | error_code = response_json.get("error_code") |
| 89 | if error_code not in ERROR_CODE_EXCEPTIONS: |
| 90 | return |
| 91 | |
| 92 | message = response_json.get("message", "") |
| 93 | |
| 94 | if error_code == "FunctionalRequirementTooComplex": |
| 95 | raise plain2code_exceptions.FunctionalRequirementTooComplex( |
| 96 | message, response_json.get("proposed_breakdown") |
| 97 | ) |
| 98 | if error_code == "MissingResource": |
| 99 | raise plain2code_exceptions.MissingResource(f"Missing resource: {message}\n") |
| 100 | if error_code == "ConflictingRequirements": |
| 101 | raise plain2code_exceptions.ConflictingRequirements(f"Conflicting requirements: {message}\n") |
| 102 | if error_code == "RenderingCreditBalanceTooLow": |
| 103 | raise plain2code_exceptions.RenderingCreditBalanceTooLow(message) |
| 104 | if error_code == "LLMInternalError": |
| 105 | raise plain2code_exceptions.LLMInternalError(f"LLM internal error: {message}\n") |
| 106 | if error_code == "PlainSyntaxError": |
| 107 | raise plain2code_exceptions.plain_syntax_error(message or "Unknown error") |
| 108 | if error_code == "InternalServerError": |
| 109 | raise plain2code_exceptions.InternalServerError( |
| 110 | "Internal server error.\n\n" |
| 111 | "Please report the error to support@codeplain.ai with the attached .log file." |
| 112 | ) |
| 113 | exception_class = ERROR_CODE_EXCEPTIONS[error_code] |
| 114 | raise exception_class(message) |
| 115 | |
| 116 | def post_request( |
| 117 | self, |