In the daily operation and development of Anqi CMS, we often need to obtain the content of the website through API interfaces, including the "interface for obtaining document details" (/api/archive/detailIt is undoubtedly one of the most frequently used ones. This interface allows us to retrieve the details of a specific article or product through the document ID or URL alias (filename).However, it is inevitable that we will encounter such situations in the process of using it: What kind of error message will the interface return when the requested document does not exist in the system?This is crucial for front-end page display, back-end logic judgment, and error log recording.
First, let's review the basic operation of the "get document details" interface. When a document (such as an article, a product page) is accessed through its unique ID or a custom URL alias (filenameWhen requested, if the document indeed exists in the AnQi CMS, the interface usually returns a successful response. This means that the response'scodeField is0,msgfield is empty, anddataThe field will contain all the detailed data of the document, such as title, content, SEO information, etc.
How will the interface respond when the requested document ID or filename points to a non-existing document?According to the design specifications of AnQi CMS API, in this case, the interface will return a clear error prompt.In particular, the response structure will be like this:
{
"code": -1,
"msg": "文档不存在",
"data": null
}
From this return example, we can clearly see several key points:
codeThe field becomes-1This indicates a general business logic error. In the AnQi CMS error code system,0usually represents success, whereas-1indicates that an error has occurred, and the specific cause needs to be combined withmsgField to judge.msgThe field will provide specific error reasonsIn this case,msgIt will clearly display "The document does not exist." This is a very friendly prompt, which directly tells us that the requested content was not found.In practice, based on the CMS configuration or version, this information may have subtle differences, but the core meaning is to indicate that resources are missing.dataField isnullSince the document itself does not exist, it is naturally impossible to return any document detail data, thereforedataThe field will be a null value(nullThis returns the next or previous document interface when there is no corresponding documentdata: nullThe logic is consistent, maintaining the consistency of the API return results
Understanding this error prompt mechanism is very important for developers and website operators. On the frontend, we can according tocodeWith-1andmsgIn the case of a "document not found" situation, display a friendly "404 page" or "content not found" prompt to the user instead of a harsh system error.In backend processing, we can use this information to log, analyze invalid requests, or trigger other business logic, such as jumping to the relevant content list page.
Frequently Asked Questions (FAQ)
Q1: If I do not provideidnor providefilenamewhen requesting the 'Get Document Details' interface, what kind of error will be returned?A1: If neitheridis provided in the request parametersfilenameThis belongs to the error of incomplete or non-standard request parameters. The interface usually returnscode: -1and then inmsgThe error indicated is a missing or invalid parameter, such as 'parameter error' or 'missing required parameters'. This error is on a different level from 'document not found'.
Q2: Besidescode: -1the document also mentioned,1001/1002such error codes, what is the difference between them and 'document not found'?A2:code: -1It usually indicates an error at the business logic level, such as 'The document does not exist' is a business logic error. And like1001(Not logged in),1002An unauthorized error belongs to the permission verification level. This means that even if the document exists, if the user does not have the corresponding permission to access, these permission-related error codes will be returned.200Although it is also listed as an error code, it usually indicates success in HTTP status codes, in the design of Anqi CMS APIs,code: 0which is the sign of business success.
Q3: The “document does not exist” ofmsgCan the content “document does not exist” be customized to other more personalized text?A3: The interface returns themsgThe field content is usually preset by the AnQi CMS backend program.If you need to customize these prompt messages, you usually need to modify the backend code of AnQi CMS or through the CMS provided internationalization (i18n) or language package management function.On a pure API call level, we cannot directly modifymsgtext content of the field.