valid-error-template-message
Overview
This rule belongs to the apimatic-codegen-validation
ruleset and states that:
Value of an error template entry must be a valid string message, with support for expression templates. A template must start and end with curly braces {} and contain a valid expression in between. The templates are filled with actual data at runtime. Allowed template expression placeholders include: {$statusCode}, {$response.header.<headerKey>}, {$response.body<#JsonPointer>}. If {$response.header.<headerKey>} placeholder is used, <headerKey> must be replaced with a valid response header name. <#JsonPointer> in the {$response.body<#JsonPointer>} placeholder is an optional segment that can be used to access a particular part of a JSON response body. If used, it must follow valid JSON pointer syntax.
Property | Value |
---|---|
Enabled | Yes |
Maximum Severity | Error |
Message | Error template message is invalid. |
Code | APIMATICCODEGEN_V502 |
Type | Validation |
Rule System | Semantic |
Products Impacted | Code Generation, Developer Experience Portal |
Tags | apimatic code generation codegen sdks portal docs validation apimatic error template template runtime expression expression errors exceptions codegen setting endpoint setting |
Suggested Fixes
- Ensure that any curly braces in the error template message are correctly balanced i.e. there are no missing starting or ending curly braces or extra braces present.
- Make sure that reserved placeholders like $statusCode, $response.header, $response.body are correctly spelled. The placeholder names are compared in a case-sensitive manner.
- If you are using the {$response.body<#JsonPointer>} placeholder, make sure that you are using valid JSON pointer syntax. A valid error message example for this case:
An error has occurred: {$response.body#/errors/0/reason}
- An error template is used for generating meaningful exception messages in SDKs.
For More Information
- https://www.rfc-editor.org/rfc/rfc6901
- https://docs.apimatic.io/define-apis/endpoints/#error-response-codes
- https://docs.apimatic.io/api-editor/codegen-settings/
- https://docs.apimatic.io/define-apis/endpoints/#advanced-settings
- https://www.apimatic.io/continuous-code-generation
- https://docs.apimatic.io/rulesets/overview/