In the daily operation and development of AnQi CMS, we often need to obtain the content of the website through API interfaces, among which 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 detailed information of a specific article or product by document ID or URL alias (filename).However, during use, it is inevitable that we will encounter such situations: when the requested document does not exist in the system, what kind of error prompt will the interface return?This is crucial for front-end page display, back-end logic judgment, and error log recording.
Let's review the basic operation of the "Get Document Details" interface. When a document (such as an article, a product page) is accessed by its unique ID or a custom URL alias (filename)be requested, if the document indeed exists in the security CMS, the interface usually returns a successful response. This means that the responsecodethe field is0,msgfield is empty, anddataThe field will include all detailed data of the document, such as title, content, SEO information, etc.
Then, how will the interface respond when the requested document ID or filename points to a non-existent document?According to the design specifications of the Anqi CMS API, in this case, the interface will return a clear error prompt.
{
"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 error code system of AnQi CMS,0usually represents success,-1indicating that some error has occurred, the specific cause needs to be combined withmsgField to judge.msgField will provide specific error reasonsIn this example,msgIt will clearly show "The document does not exist."This is a very friendly prompt, it directly tells us that the requested content was not found.In fact, depending on the CMS configuration or version, this information may have subtle differences, but the core meaning is to indicate that resources are missing.datathe field isnullSince the document itself does not exist, it is naturally not possible to return any document detail data, thereforedataThe field will be an empty value (null) This is returned by the 'get next document' or 'get previous document' interface when no corresponding document is founddata: 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 front end, we can according tocoderesponse for-1andmsgFor the case of "document not foundIn backend processing, we can use this information to log, analyze invalid requests, or trigger other business logic, such as jumping to the related content list page.
Frequently Asked Questions (FAQ)
Q1: If I do not provide the parameters for the "get document details" interface request,idneitherfilename, what kind of error will be returned?A1: If there are no parameters in the requestidneitherfilenameThis belongs to an error where the request parameters are incomplete or do not meet the specifications. The interface usually returnscode: -1andmsgThe error points out that the parameter is missing or invalid, for example, "Parameter error" or "Missing required parameter". This error is a different level of issue from "Document not found".
Q2: Besidescode: -1The document also mentions,1001/1002What are the differences between these error codes and "document not found"?A2:code: -1usually indicates an error in the business logic layer, such as “The document does not exist” is a business logic error. And like1001(not logged in),1002(Unauthorized) is an error on the permission verification level.This means that even if the document exists, if the user does not have the corresponding permissions to access it, 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's API,code: 0which is the business success indicator.
Q3: “Document does not exist”msgCan the content “Document does not exist” be customized to other more personalized text?A3: The interface returnsmsgThe field content is usually preset system messages by the backend program of Anqi CMS.If you need to customize these prompt messages, you usually need to modify the backend code of the Anqi CMS or implement it through the CMS provided internationalization (i18n) or language package management function.msgthe text content of the field.