During the operation and development of the website, we often use the various API interfaces provided by Anqi CMS to dynamically obtain and display content. Among them,archiveFiltersThe interface plays an important role, it can help us obtain the filtering conditions of the document, thus providing users with a more refined browsing experience.However, properly handling the error codes returned by any API is the key to ensuring the stability of the website and a smooth user experience.
This article will delve deeper intoarchiveFiltersThe interface may return several error codes (such as-1/1001/1002), and provide specific strategies for dealing with them to help you better manage your website content.
UnderstandarchiveFiltersThe importance of the interface
Imagine that you are building a content-rich website, such as a recruitment platform, or a product display page.Users hope to be able to quickly find content of interest based on conditions such as 'city', 'education', 'product type', etc.archiveFiltersThe interface is exactly for this. It can be based on the model ID you specify.moduleId),Dynamically returns all available filter fields and option lists under the model.This allows the front end of the website to flexibly build filters, greatly improving the efficiency and convenience of users searching for information.
When you send{域名地址}/api/archive/filtersa GET request and pass a validmoduleIdWhen, in an ideal case, we would receive a successful response containing a list of filter conditions. But if unexpected results occur, we need to pay attention to the returnedcodefield.
error code analysis and response
archiveFiltersThe response of the interface contains,codeThe field is the key to judge the request status. Usually,code: 0orcode: 200it represents a successful request. Whilecodeother values, we need to handle them specifically.
1.code: -1:General error, details seemsgField
When you seecodeReturns-1, this usually means that the server encountered some internal error or business logic problem while processing your request. At this time,msgThe field becomes particularly important as it provides specific error reasons.
Possible causes:
- Invalid
moduleId:The model ID you entered may not exist, or it may not be suitable for obtaining filtering conditions. - Back-end configuration issue:There may be some incorrect model or filter condition configurations in the Anqi CMS backend, which may cause the interface to generate data abnormally.
- Internal server error:Database connection failure, program logic errors, and other unexpected situations.
Response strategies:
- Read carefully
msgFields:This is the solution-1The first step in correcting an error and also the most critical step.msgThe field will tell you whether it is a "Invalid model ID - Check
moduleId:Confirm the one you have entered.moduleIdIs it correct, and does it truly exist in the Anqicms CMS backend, and does it include configurable filtering fields? - Check the Anqicms CMS backend configuration:If
msgThe prompt is related to configuration issues, please log in to the Anqi CMS backend and check whether the filter field settings under the corresponding model are complete and correct. - Record the error and contact technical support:If
msgInformation is still unclear, or you cannot solve it yourself, please provide the complete error response (includingcodeandmsgRecord it and contact the CMS technical support team of AnQi, they will provide more professional help based on the logs. - Front-end friendly prompt:On the front-end page, you can display a generic 'Loading filter conditions failed, please try again later' or 'System busy' and other friendly prompts to avoid exposing technical error information directly and guide users to retry or visit later.
2.code: 1001:Not logged in
code: 1001is a very clear prompt: The request you initiated was rejected because it lacks valid user login credentials. This usually happensarchiveFiltersThe interface is set to require user authentication to access, and the current user is not logged in, or their login credentials have expired.
Possible causes:
- The user is not logged in:The website current user is in a visitor state, but the interface requires login user permission.
- Login session expired:The user has logged in before, but the session has expired and needs to log in again.
- Missing or incorrect authentication information:The authentication Token (such as JWT) was not carried or carried incorrectly in the API request, causing the server to be unable to identify the user's identity.
Response strategies:
- Check user login status:When calling
archiveFiltersBefore the interface, first check if the user is logged in. - Guide the user to log in:If the user is not logged in, and the filtering feature indeed requires login to use, the user should be redirected to the login page. After logging in successfully, try to call it again.
archiveFiltersinterface. - Refresh the authentication Token:If a session has expired, try using the Refresh Token mechanism (if your authentication system supports it) to obtain a new Access Token, or guide the user to log in again.
- Ensure the request carries authentication information:Check your API request code to ensure that the correct authentication Token is included in the HTTP header when sending the request (for example
Authorization: Bearer <您的Token>).
3.code: 1002Unauthorized
With1001different,code: 1002Means that although you are logged in, your current account or role does not have sufficient permissions to access or operate this specific filter condition.This is like you holding a access card to enter the company building, but unable to open the door of a specific office because that office requires higher privileges.
Possible causes:
- User does not have sufficient privileges:The role of the current logged-in user (such as, ordinary user, VIP user) is restricted, and they do not have access to certain
moduleIdfilter conditions. - Resource access strategy:English CMS background for
archiveFiltersinterface or access to a specific model is restricted.
Response strategies:
- Prompt user insufficient permissions:On the front-end page, clearly inform the user that "You do not have permission to access this filtering feature", or "Your account level is insufficient to use this feature".
- Hide or disable the feature entry:On the user interface, if the user does not have permission, it is advisable to avoid displaying related filters or gray them out to prevent the user from attempting to click and realizing they do not have access. This helps to improve the user experience.
- Check the user group permissions of the AnQi CMS backend:As a website administrator, you need to log in to the Anqi CMS backend to check whether the user group of the current user has been granted the permission to access the related model filtering conditions.When necessary, adjust user group permissions or prompt the user to upgrade the account.
Summary
Handle AnQi CMS correctlyarchiveFiltersThe returned error code from the interface is not only a necessary operation on the technical side, but also a crucial link to improve the user experience of the website and ensure the stable operation of the system.By understanding the meaning behind each error code and taking the corresponding diagnostic and resolution measures, you can make the website's content filtering function more robust and user-friendly.Always remember, clear error messages, appropriate user guidance, and timely backend troubleshooting are the three great weapons to solve API interface problems.
Common Questions (FAQ)
Q1: Why did I receive-1Error, butmsgIs the field unclear, only displaying general information like 'Request failed'?A1: WhenmsgThe field is also quite general, usually indicating that the error occurs at a lower level or information is lost when the error is caught.This may require you to check the server-side log files to obtain more detailed error stack information, thereby locating specific code issues or configuration anomalies.If you cannot access the server log, it is recommended to contact your server administrator or the CMS technical support team.
Q2:1001(Not logged in) and1002How to distinguish user guidance in practice for (unauthorized)?A2:1001The user identity is unknown. The most direct guidance is to prompt the user to 'Please log in before attempting this operation' and provide a login entry.1002Indicates that the user identity is known but the permissions are insufficient. In this case, it should prompt 'Your account does not have permission to access this feature' and can provide options such as 'Upgrade account' or 'Contact administrator' instead of simply logging in again.
Q3:archiveFiltersWhat conditions would cause the interface to return a large amount or no filtering criteria?A3: IfmoduleIdImproper specification, or no filterable fields are configured for this model in the Security CMS backend.archiveFiltersThe interface may return an emptydataarray, this is not an error but a normal situation.