How to properly handle the error codes returned by the `archiveFilters` interface (such as -1, 1001, 1002)?

Calendar 78

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

Related articles

What would the `archiveFilters` interface return if a document model does not have filterable custom fields?

In Anqi CMS, the `archiveFilters` interface is a very practical feature that allows us to retrieve the filtering conditions of specific document models, thereby helping users to implement flexible content filtering on the front-end page.For example, on a product display page, we may need to filter products based on attributes such as 'color', 'size', or 'brand'. What if a document model is exactly configured without any filterable custom fields, what will the `archiveFilters` interface return?

2025-11-09

Does the `archiveFilters` interface support retrieving filtering conditions based on a specified category ID?

When using Anqi CMS for website content management, flexibly obtaining and displaying filter conditions is a key link in improving user experience.Many friends may wonder when using the `archiveFilters` interface whether it supports retrieving filtering conditions based on specified category IDs to provide more accurate filtering options for different categories.Today, let's delve deeply into this issue.

2025-11-09

In what scenario should `archiveFilters` be used instead of `archiveParams`?

During the development and content management of Anqi CMS, we often need to obtain relevant information about documents (Archive).Among them, `archiveFilters` and `archiveParams` are two API interfaces closely related to custom fields, but their design purposes and application scenarios are different.Understanding the difference between them can help us build website features more efficiently and enhance the user experience.First, let's briefly understand the core functions of these two interfaces.

2025-11-09

What is the difference between the interface for getting document parameters (`archiveParams`) and the interface for getting document parameter filtering conditions (`archiveFilters`)?

When using AnQiCMS for website content management, we often need to deal with document-related API interfaces.Among them, the interface names `archiveParams` and `archiveFilters` sound similar at first glance, and they are both related to Understanding the differences between them can help us develop and manage websites more efficiently.

2025-11-09

Does the `archiveFilters` interface require user login authorization to access?

In the daily application of Anqi CMS, the `archiveFilters` interface is an important tool for dynamically displaying filter conditions on the front-end page. It allows the website to generate various filter options based on the field configuration of the article model, such as "city", "education", and so on.It is crucial for building a user-friendly content browsing experience, where users can quickly locate content of interest through these filtering conditions.However, many developers may have a question when integrating: does this interface require user login authorization to access?To answer this question

2025-11-09

How to dynamically build a frontend filtering UI based on the response of `archiveFilters`, such as dropdown menus or checkboxes?

In today's increasingly rich content of websites, how to allow users to quickly find the information they are interested in is a crucial operational issue.AnQiCMS provides powerful content management capabilities, and its API interface provides a solid foundation for front-end developers to build flexible and varied interactive interfaces.Today, let's delve into how to use the response data from the `archiveFilters` interface to dynamically build front-end filtering UI, such as common dropdown menus or checkboxes.The value of dynamic filtering interface Imagine that

2025-11-09

How to get the latest document list of the specified model (`moduleId`) through AnQiCMS?

In website content management, we often need to dynamically display the latest updates of a certain type of content, such as news articles, product releases, or blog updates.For websites built using AnQiCMS, leveraging its powerful API interface to obtain the latest document list under a specified model is a very basic and practical operation.This can not only help developers build dynamic pages quickly, but also provide users with timely updated information, optimizing the user experience of the website.To implement this feature, we mainly use the AnQiCMS provided

2025-11-09

What is the main difference between the `type="page"` and `type="list"` modes in the AnQiCMS document list interface?

When you are using AnQiCMS to build a website and need to retrieve document content from the backend, you will often encounter the document list interface (/api/archive/list).This interface provides a very important `type` parameter, which determines how you will obtain and process the document list data.A deep understanding of the core differences between the `type="page"` and `type="list"` modes is crucial for improving website performance, optimizing user experience, and developing more flexible features.###

2025-11-09