During website operation and development, we often use the various API interfaces provided by Anqi CMS to dynamically obtain and display content. Among which,archiveFiltersThe interface plays an important role, it helps us get the document filtering conditions, thus providing users with a more refined content browsing experience.However, correctly handling the error codes returned by any API is crucial to ensure the stable operation of the website and a smooth user experience.

This article will delve deeper intoarchiveFiltersInterface may return several error codes (such as-1/1001/1002), and provide specific strategies to help you better manage website content.

UnderstandarchiveFiltersThe importance of interfaces and their significance

Imagine that you are building a rich content website, such as a job 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.Safe CMS ofarchiveFiltersThe interface was created for this. It can be according to the model ID you specified.moduleId), dynamically returns the list of all available filter fields and option lists under the model.This allows the website frontend to flexibly build filters, greatly improving the efficiency and convenience of users searching for information.

When you send to{域名地址}/api/archive/filtersSend a GET request and pass a validmoduleIdWhen, ideally, you 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 handling

archiveFiltersthe interface returns,codethe field is the key to judging the request status. Usually,code: 0orcode: 200represents success. Whencodeis other values, we need to handle it specifically.

1.code: -1: General error, see detailsmsgfield

When you seecodeReturn-1this 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 reasons:

  • InvalidmoduleId:The model ID you entered may not exist or may not be suitable for retrieving filter conditions.
  • Backend configuration issue:There may be some incorrect model or filter condition configuration in the AnQi CMS backend, causing the interface to generate data normally.
  • Internal server error:Database connection failed, program logic errors, and other unexpected situations.

Response strategies:

  • Read carefullymsgField:This is the solution to-1the first step in correcting errors and is also the most critical step.msgThe field will tell you specifically whether it is an invalid "model ID", a configuration error of the filtering conditions, or some other issue.
  • CheckmoduleId:Confirm the one you have entered.moduleIdIs it correct and truly exists in the Anq CMS backend, and includes configurable filtering fields.
  • Check the Anq CMS backend configuration:IfmsgThe prompt is related to configuration issues, please log in to the AnQi CMS backend and check if the filter field settings under the corresponding model are complete and correct.
  • Record the error and contact technical support:IfmsgThe information is still vague, or you cannot solve it yourself, please include the complete error response (includingcodeandmsg)Record it and contact the technical support team of AnQi CMS, they will provide more professional assistance based on the logs.
  • Front-end friendly prompt: On the front-end page, you can display a general prompt such as

2.code: 1001: Not logged in

code: 1001It is a very clear prompt: Your request was rejected because it was missing valid user login credentials. This usually happens whenarchiveFiltersThe interface is set to require user authentication to access, but the current user is not logged in, or their login credentials have expired.

Possible reasons:

  • User is not logged in: The current user of the website is in a visitor status, but the interface requires login user privileges.
  • 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 API request did not carry or carried an incorrect authentication token (such as JWT), causing the server to be unable to identify the user's identity.

Response strategies:

  • Check user login status:When callingarchiveFiltersBefore 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 filter function indeed requires login to use, the user should be redirected to the login page. After successful login, try calling it again.archiveFiltersinterface.
  • Refresh the authentication Token:If the 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 that the request carries authentication information:Check your API request code, make sure that the correct authentication Token is included in the HTTP header when sending the request (for exampleAuthorization: Bearer <您的Token>)

3.code: 1002: Unauthorized

with1001different,code: 1002Meaning that although you have logged in, the account or role you are currently using does not have sufficient permissions to access or operate this specific filter condition.This is like you entering the company building with a card access, but unable to open the door of a specific office, because that office requires higher permissions.

Possible reasons:

  • Insufficient user privileges:The role of the currently logged-in user (such as, ordinary user, VIP user) is restricted and has no access to somemoduleIdfilter conditions.
  • Resource access policy:Secure CMS backend access setarchiveFiltersAccess to interfaces or specific models has set permission restrictions.

Response strategies:

  • Prompt the user that the permission is insufficient:On the front-end page, explicitly inform the user that "You do not have permission to access this filter function", or "Your account level is insufficient to use this feature".
  • Hide or disable the function entry:On the user interface, if the user does not have permission, it should avoid displaying related filters or gray them out to prevent the user from trying to click and finding out that they do not have access, which helps 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 Anqicms backend and check whether the user group to which the current user belongs has been granted access to the related model filtering conditions.It is necessary to adjust user group permissions or prompt users to upgrade their accounts.

Summary

Handle AnQi CMS correctlyarchiveFiltersThe error code returned by the interface is not only a necessary operation from a technical perspective, but also an important factor in improving the user experience of the website and ensuring the stable operation of the system.By understanding the meaning behind each error code and taking 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.

Frequently Asked Questions (FAQ)

Q1: Why did I receive-1Error, butmsgThe field is very vague, only showing general information such as 'request failed'?A1: WhenmsgWhen a field is also general, it usually means 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 logs, it is recommended to contact your server administrator or the security CMS technical support team.

Q2:1001(Not logged in) and1002(Unauthorized) How to distinguish user guidance in practical applications?A2:1001Indicating that the user's identity is unknown, the most direct guide is to prompt the user to 'login again before attempting this operation' and provide a login entry. And1002Indicates that the user's 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 offer options such as 'Upgrade account' or 'Contact the administrator' instead of simply logging in again.

Q3:archiveFiltersUnder what circumstances will the interface return a large amount or no filtering conditions?A3: IfmoduleIdImproper specification, or the model is not configured with any filterable fields in the AnQi CMS backend,archiveFiltersThe interface may return an emptydataarray, this is not an error, but a normal situation of the