Network Request Processing Method, Apparatus, Device, and Program Product
By inserting global error conversion classes into network request processing, network request errors are handled uniformly, the problems of high development costs and poor code readability are solved, and the effect of code simplification and maintenance costs are achieved.
Patent Information
- Application Number
- CN202510173901.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-18
- Publication Date
- 2025-06-13
- Estimated Expiration
- 2045-02-18
AI Technical Summary
The prior art has high development costs in network request processing and poor code readability, which is not conducive to reducing maintenance difficulty.
By inserting the global error conversion class into the observable object generated by network requests, all errors are handled uniformly, callback nesting is reduced, and error handling logic is simplified.
Reduces the volume of code development, improves code readability, simplifies the maintenance process, and reduces maintenance costs.
Smart Images

Figure CN119645714B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of network data processing, and in particular to a network request processing method, apparatus, device, and program product. Background Art
[0002] During the development of Android applications, developers are faced with the rapid changes and diversification of functional requirements, which means that each App may have unique operation requirements and communication protocols with the server. This diversity and complexity bring a series of challenges, especially in network request processing. Network requests are often affected by factors such as network fluctuations, server errors, and data format mismatches. Therefore, each request needs to be handled for exceptions to ensure the stability of the App and the user experience.
[0003] However, due to the instability of the network environment, the variability of the server state, and the complexity of the protocol between the client and the server, network requests often encounter various abnormal situations. The traditional processing method is usually to handle abnormal situations by means of interface calls after each network request. Although this method can achieve asynchronous data processing, however, each network request needs to be handled for exceptions, resulting in a large development time cost and labor cost. And in order to handle complex situations, developers may need to nest multiple callbacks in the callback, resulting in poor code readability and being not conducive to reducing the maintenance difficulty. Summary of the Invention
[0004] In view of this, embodiments of the present application provide a network request processing method, apparatus, device, and program product to solve the problems in the prior art that when performing network request processing, the development cost is high, the code readability is poor, and it is not conducive to reducing the maintenance difficulty.
[0005] The first aspect of the embodiments of the present application provides a network request processing method, and the method includes:
[0006] Send a network request to obtain a first observable object generated by the network request;
[0007] Insert a global error conversion class into the first observable object through a combination operator to obtain a second observable object, where the global error conversion class is used to uniformly process according to the type of global error;
[0008] Receive the response data of the network request, and perform conversion processing on the response data through the global error conversion class to obtain a processing result corresponding to the response data.
[0009] In combination with the first aspect, in the first possible implementation manner of the first aspect, receiving the response data of the network request, and performing conversion processing on the response data through the global error conversion class to obtain the processing result corresponding to the response data, including:
[0010] Receiving the response data of the network request through the base class, where the base class includes a status code, returned data, and a prompt message;
[0011] The global error conversion class performs conversion processing on the response data according to the status code, returned data, and prompt message included in the base class to obtain the processing result corresponding to the response data.
[0012] In combination with the first possible implementation manner of the first aspect, in the second possible implementation manner of the first aspect, the global error conversion class performs conversion processing on the response data according to the status code, returned data, and prompt message included in the base class to obtain the processing result corresponding to the response data, including:
[0013] Determining the response type corresponding to the status code of the base class according to the predefined correspondence between the status code and the response type;
[0014] Performing conversion processing on the response data through the global error conversion class according to the response type to obtain the processing result corresponding to the response data.
[0015] In combination with the second possible implementation manner of the first aspect, in the third possible implementation manner of the first aspect, performing conversion processing on the response data through the global error conversion class according to the response type to obtain the processing result corresponding to the response data, including:
[0016] When the response type is a normal response, transmitting the returned data included in the base class downstream;
[0017] When the response type is an abnormal response, mapping the status code and prompt message in the base class to a globally converted error code and text description information according to the preset mapping relationship to obtain the processing result corresponding to the response data.
[0018] In combination with the second possible implementation manner of the first aspect, in the fourth possible implementation manner of the first aspect, performing conversion processing on the response data through the global error conversion class according to the response type to obtain the processing result corresponding to the response data, including:
[0019] When the response type is a retry type, determining to re-execute the second observable object according to the retry operator.
[0020] Combined with the fourth possible implementation manner of the first aspect, in the fifth possible implementation manner of the first aspect, the type to be retried includes at least one of a network exception type and a server failure type.
[0021] Combined with the first possible implementation manner of the first aspect, in the sixth possible implementation manner of the first aspect, the global error conversion class performs conversion processing on the response data according to the status code, the returned data, and the prompt message included in the base class, to obtain the processing result corresponding to the response data, including:
[0022] When the global error conversion class determines that the returned data included in the base class is unexpected data, it converts the returned data into abnormal data;
[0023] According to the correspondence between the abnormal data and the globally converted error code and text description information, it determines the error code and text description information included in the processing result of the returned data.
[0024] A second aspect of the embodiments of the present application provides a network request processing device, and the device includes:
[0025] A first observable object generation unit, configured to send a network request and obtain a first observable object generated by the network request;
[0026] An insertion unit, configured to insert a global error conversion class into the first observable object through a combination operator to obtain a second observable object, where the global error conversion class is used for unified processing according to the type of global error;
[0027] A conversion processing unit, configured to receive the response data of the network request and perform conversion processing on the response data through the global error conversion class to obtain the processing result corresponding to the response data.
[0028] A third aspect of the embodiments of the present application provides a network request processing device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the network request processing device implements the method according to any one of the first aspect.
[0029] A fourth aspect of the embodiments of the present application provides a computer program product, which when running on a computer, causes the computer to execute the method in the above first aspect or its various implementation manners.
[0030] A fifth aspect of the embodiments of the present application provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the steps of the method according to any one of the first aspect.
[0031] The sixth aspect of the embodiments of the present application provides a chip for implementing the methods in the various implementation manners of the first aspect above. Specifically, the chip includes: a processor for calling and running a computer program from a memory, so that a device installed with the chip executes the methods in the first aspect or its various implementation manners as described above.
[0032] The beneficial effects of the embodiments of the present application compared with the prior art are as follows: In the method for processing network requests in the embodiments of the present application, for the first observable object generated according to the network request, a global error conversion class is inserted into the first observable object through a combination operator to obtain a second observable object. The response data of the network request is received through the second observable object, and all errors are uniformly processed by the global error conversion class. No matter what error the network request returns, it can be processed through this conversion class, so that developers do not need to nest multiple callbacks in the callback, reducing the amount of code development. Only the global error conversion class needs to be updated, which is beneficial to reducing the maintenance cost and improving the readability of the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0034] Figure 1 is a schematic diagram of an implementation scenario of a network request processing method provided by an embodiment of the present application;
[0035] Figure 2 is a schematic diagram of an implementation process of a network request processing method provided by an embodiment of the present application;
[0036] Figure 3 is a schematic diagram of an implementation process of a conversion processing method provided by an embodiment of the present application;
[0037] Figure 4 is a schematic diagram of an implementation process of a network request processing method provided by an embodiment of the present application;
[0038] Figure 5 is a schematic diagram of a network request processing device provided by an embodiment of the present application;
[0039] Figure 6 is a schematic diagram of a network request processing device provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0040] In the following description, specific details such as specific system architectures and technologies are presented for the purpose of illustration rather than limitation, so as to thoroughly understand the embodiments of the present application. However, those skilled in the art should clearly understand that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of the present application.
[0041] To illustrate the technical solutions described in the present application, the following will be described through specific embodiments.
[0042] In the current App development process, in the face of the ever-changing functional requirements and operation requirements of the APP, developers need to address a series of challenges, especially in the data processing of network requests. The following are some specific challenges and problems, as well as their impacts on the development process:
[0043] 1. Complexity of functional requirements: Modern Apps usually include multiple functions such as social networking, payment, and multimedia processing, and these functions may involve complex business logics. The complexity of functional requirements leads to more diverse network requests, and each request may need to handle different data structures and error situations.
[0044] 2. Differences in operation requirements: Different Apps may have different requirements for user operations, such as login authentication, data synchronization, real-time updates, etc. These differences in operation requirements mean that each network request requires specific processing logics, including the construction of request parameters, the parsing of response data, and error handling.
[0045] 3. Differences in the protocols agreed with the server: Each App may have different data exchange protocols with the backend server, such as RESTful API, GraphQL, etc. The differences in protocols result in the diversity of network requests, and developers need to write specific processing codes for each protocol.
[0046] 4. Complexity of exception handling: Various exceptions may occur during the network request process, such as network errors, server errors, data parsing errors, etc. Each request requires targeted exception handling logics, which increases the complexity of the code and the development workload.
[0047] In traditional Android development, network requests are usually processed through interface callbacks, such as using AsyncTask, Handler (both AsyncTask and Handler are tools for handling asynchronous tasks and thread operations on the Android platform), or callback interfaces. This processing method easily leads to multi-level nesting of code, making the code difficult to read and maintain. Moreover, the multi-level nested callback code makes the execution flow of the code difficult to track. Developers newly joining the project need to spend more time understanding the existing code structure, making the code less readable and making code review and testing more difficult.
[0048] Figure 1 It is a schematic diagram of an implementation scenario for network request processing provided by an embodiment of this application. This implementation scenario includes a client 1 and a server 2. Among them, the client 1 can send a network request to the server 2. The server can parse the network request, execute necessary business logic, access a database or other data sources, and generate response data, and send the response data to the client 1. When sending a network request, the client 1 will generate a first observable object according to the network request, and insert a global error conversion class into the first observable object through a combination operator to obtain a second observable object. For the response data of the received network request, it can be processed through the global error conversion class in the second observable object to obtain the processing result corresponding to the response data. Through the unified processing of the global error conversion class of the second observable object, no matter what error the network request returns, it can be processed through this conversion class, so that developers do not need to nest multiple callbacks in the callback, reducing the code development volume. Only the global error conversion class needs to be updated, which is beneficial to reducing the maintenance cost and improving the code readability.
[0049] Figure 2 An embodiment of this application proposes a network request processing method, and this network request processing method includes:
[0050] In S201, send a network request to obtain the first observable object generated by the network request.
[0051] On the APP side (i.e., the client), a network request interface can be predefined. The interface describes the detailed information required for the client to communicate with the server, including one or more of information such as the request URL, request method, required request headers, or request body. According to the predefined network request interface, a network request service is created. For example, it can be implemented through network libraries for creating network requests such as Retrofit, Volley, or OkHttp.
[0052] While the client sends a network request to the server, embodiments of the present application can use a reactive programming library, such as RxJava, to create an observable object, namely the first observable object (observable1).
[0053] Among them, RxJava is an asynchronous programming framework applied in development. RxJava can be based on the extended observer design pattern and has a high degree of simplicity. RxJava can make the code call process clearly visible through chained calls. Various asynchronous operations can be organized in sequence. When processing asynchronous data streams, a series of transformations such as filtering, transforming, and merging the sent messages can be performed through rich operators to meet the data processing requirements in different scenarios.
[0054] It can be understood that it is not limited to RxJava, and reactive programming libraries such as Kotlin Flow and ProjectReactor can also be used to create the first observable object.
[0055] Among them, the first observable object is an observable object, and its English name is observable. An observable object is a data stream that can emit events and is also an observable data source. The observable object can emit a series of events, and these events can be data items, errors, or completion signals. The observable can interact with an observer through a subscription mechanism. After the observer subscribes to the observable, it can receive the events emitted by the observable.
[0056] After sending the network request, the network request can be automatically encapsulated as the first observable object through the support of reactive programming provided by the network library. Or, the first observable object can also be automatically generated after detecting the sending of the network request.
[0057] In S202, a global error conversion class is inserted into the first observable object through a combination operator to obtain a second observable object.
[0058] Among them, the global error conversion class is used to uniformly process according to the type of global error, encapsulate various different exception situations into a unified format, so that the front end or other callers can understand and process these errors in a consistent manner.
[0059] When processing, modifying, or replacing the first observable object, a global error conversion class can be inserted into the first observable object through a compose operator to obtain a second observable object.
[0060] Among them, the global error conversion class is used to uniformly handle various errors that may occur in network requests, convert the errors into a unified format, making the error handling logic more centralized and consistent. By converting errors into a unified format, it simplifies the error handling by downstream logic, reduces duplicate error handling code, and improves the maintainability and readability of the code.
[0061] The definition of the global error conversion class can be completed first, and then the defined global error conversion class is applied to the first observable object observable1 by using the compose operator to obtain the second observable object observable2, that is, the first observable object observable1 with the global error conversion class inserted or applied.
[0062] In S203, the response data of the network request is received, and the response data is converted and processed through the global error conversion class to obtain the processing result corresponding to the response data.
[0063] Among them, the response data of the network request may include information such as status code, returned data (Response Data), and prompt message (Message). The status code is an important part of the server response, usually a numeric code used to represent the processing result of the request. Common status codes include:
[0064] 200: Success. Indicates that the network request has been successfully processed by the server.
[0065] 400: Client error. Indicates that the network request has a syntax error or the request cannot be processed.
[0066] 401: Unauthorized. Indicates that the network request requires user authentication.
[0067] 403: Forbidden. Indicates that the server understands the request but refuses to execute it.
[0068] 404: Not Found. Indicates that the resource of the network request does not exist on the server.
[0069] 500: Internal Server Error. Indicates that the server has encountered an unexpected situation that prevents it from completing the request.
[0070] The status code enables the client to quickly understand whether the request is successful and the reason for failure.
[0071] The data returned (Response Data) is the main content of the server response, which contains the information or resources expected by the request. This data is usually encoded in JSON, XML, or other formats and can be parsed and processed by the application logic on the client side. For example, if the client requests to obtain user information from the server, the returned data may include information such as the user's name, email, address, etc.
[0072] A message is a piece of text provided by the server to the client, used to describe additional information about the response or error details. The message is usually used together with the status code to provide more specific error information to the client. For example, if the status code is 404, the message may be "The requested resource was not found", helping developers quickly locate the problem.
[0073] Embodiments of this application can receive response data through a base class to implement the processing of response data, such as Figure 3 As shown, the method includes:
[0074] In S301, the response data of the network request is received through the base class, and the base class includes a status code, the returned data, and a message.
[0075] Among them, the base class defines the structure that the network request data follows, and this structure usually includes at least a status code, the returned data, and a message. The status code is used to represent the processing result of the request, and different status codes represent different response states. The returned data is the specific business data returned by the server, which can be any type of data, such as user information, product list, etc., or a null value (the request was not successful). The message is used to provide additional information about the response status. The message can interpret the status code and can be an application-specific business logic error message.
[0076] In S302, the global error conversion class performs conversion processing on the response data according to the status code, the returned data, and the message included in the base class to obtain the processing result corresponding to the response data.
[0077] The Global Error Converter is responsible for processing the status code, the returned data, and the message in the base class and performing the following operations based on this information:
[0078] Error identification: The global error conversion class can first check the status code to determine whether the response represents a successful operation or an error. Based on the checked status code, it can be decided whether error handling logic needs to be executed.
[0079] Among them, when the global error conversion class performs conversion processing on the response data according to the status code, returned data, and prompt message included in the base class to obtain the processing result corresponding to the response data, it can determine the response type corresponding to the status code of the base class according to the correspondence between the status code returned by the network request and the response type. This correspondence can be determined according to the protocol between the client and the server or predefined information.
[0080] For example, the response types determined according to the status code returned by the network request can include types of abnormal responses such as network error, parsing error, connection failure, host exception, I / O exception, connection timeout, certificate verification failure, unknown error, etc., or can also include the type of normal response.
[0081] The global error conversion class can uniformly process different response types of different protocols and different APPs, including the processing of normal responses and abnormal responses.
[0082] When the response type is an abnormal response, the do on erro operator can be used to determine the unified error code and text description information corresponding to different error types.
[0083] For example, the correspondence between the error code and the text description information determined by the do on erro operator can include: 1101 network error, 1102 parsing error, 1103 connection failure, 1104 host exception, 1105 I / O exception, 1106 connection timeout, 1107 certificate verification failure, 500 server exception, and 1100 unknown error, etc., which are types of abnormal responses, or can also include the type of normal response.
[0084] If the parsed response type is a normal response, including when there is no abnormality in the data, the data can be passed downstream normally, including the returned data included in the base class.
[0085] If the parsed response type is an abnormal response, including when the data is abnormal data, the status code and prompt message in the base class can be mapped to the unified error code and text description information after global conversion according to the preset mapping relationship to obtain the processing result corresponding to the response data, that is, the converted error code and text description information. The user can be informed of the unified text description information and error code of the current abnormality by subscribing to the second observable object observable2.
[0086] In addition, when the embodiments of the present application perform conversion processing on response data, when it is determined that the response type is a type to be retried, according to a severe operator, such as through the retrywhen operator, the operation flow corresponding to the second observable object can be re-executed. That is, it is allowed that the completion or error notification of the second observable object determines whether to repeat the execution of the second observable object.
[0087] Among them, the type to be retried may include at least one of a network exception type and a server failure type.
[0088] When the App requests data, if there are situations such as unstable network, network request timeout or interruption, usually a retry operation can be performed. When the network problem is temporarily unstable, it is possible to successfully obtain data through retry.
[0089] The server may temporarily be in a state of high load, maintenance and upgrade, etc. In this state, it is temporarily unable to respond to requests. In this case, it is possible to successfully obtain data through a retry operation, such as by retrying the retrywhen operator and re-executing the second observable object.
[0090] For example, it is possible to retry the types of abnormal data such as error requests and authorization failures. When obtaining the response data of an error request, the network request can be resent. When the authorization fails or the signature is incorrect, it is redirected to the login page.
[0091] In the embodiments of the present application, it is also possible to determine whether the response data is the expected data. If the response data is unexpected data, that is, not the data desired by the network request, if not processed, it may cause the application to crash. In this case, in order to improve the reliability of the application operation, through an operator, such as through the onErrorResumeNext (continue with the next when an error occurs) operator, the returned normal data can be converted into abnormal data, so that through global error exception handling, including determining the error code and text description information corresponding to the unexpected data, etc.
[0092] For example, the corresponding relationship between the error code and text description information determined for the unexpected data may include: 400 Bad Request, 401 Unauthorized, 402 Signature Error, 403 Forbidden, 404 Not Allowed or 405 Parameter Error, etc.
[0093] Subscribers can subscribe to the data of the second observable object to obtain unified error codes and text description information under different applications, different operations, and different protocols, so as to effectively meet the development requirements of applications under different applications, different operations, and different protocols and improve development efficiency.
[0094] Figure 4 It is a schematic diagram of network data processing provided by the embodiments of the present application. AsFigure 4 As shown, before the client sends a network request to the server, it can detect whether there is a network. If there is no network, a prompt message indicating that there is no network is sent to the user. In the case of a network, the global error conversion class can be inserted into the first observable object generated by the network request through the compose operator to obtain the second observable object. The error type conversion is performed through the second observable object.
[0095] When the response type is a normal response, that is, when the response data is normal data, the data can be transmitted normally to the downstream.
[0096] When the response type is an abnormal response, that is, when the response data is abnormal data, the do on error operator can be used in combination with throwable parsing to obtain the text description information of the corresponding abnormal response type and the corresponding error code, including abnormal response types such as 1101 network error, 1102 parsing error, 1103 connection failure, 1104 host exception, 1105 I / O exception, 1106 connection timeout, 1107 certificate verification failure, 500 server exception, and 1100 unknown error.
[0097] When the response data is unexpected data, the onErrorResumeNext operator can be used to convert the returned normal data into abnormal data, so that the error code and text description information corresponding to the unexpected data can be determined through global error exception processing, including 400 error request, 401 authorization failure, 402 signature error, 403 interface no permission, 404 request not allowed or 405 parameter error, etc.
[0098] When an access exception occurs and a pop-up box is needed to inform the user or a heavy operation is required, the retrywhen operator can be used to determine whether a heavy operation is required based on different error types. For example, when the response type is an error request, a retry operation can be performed. When the response type is an authorization failure or a signature error, a retry operation can be performed and the login page can be returned.
[0099] In the processing method of the network request in the embodiment of the present application, according to the first observable object generated by the network request, the global error conversion class is inserted into the first observable object through the combination operator to obtain the second observable object, and the response data of the network request is received through the second observable object. All errors are uniformly processed by the global error conversion class. No matter what error is returned by the network request, it can be processed by this conversion class, so that the developer does not need to nest multiple callbacks in the callback, which greatly reduces the amount of code development. When updating the response logic, only the global error conversion class needs to be updated, which is conducive to reducing maintenance costs and improving code readability.
[0100] It should be understood that the sequence numbers of the steps in the above embodiments do not imply the order of execution. The order of execution of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
[0101] Figure 5 The figure is a schematic diagram of a network request processing device provided by an embodiment of the present application. The device includes:
[0102] A first observable object generation unit 501, configured to send a network request and obtain a first observable object generated by the network request;
[0103] An insertion unit 502, configured to insert a global error conversion class into the first observable object through a combination operator to obtain a second observable object, where the global error conversion class is used for unified processing according to the type of global error;
[0104] A conversion processing unit 503, configured to receive response data of the network request, and perform conversion processing on the response data through the global error conversion class to obtain a processing result corresponding to the response data.
[0105] Figure 5 The shown network request processing device corresponds to Figure 2 the shown network request processing method.
[0106] Figure 6 The figure is a schematic diagram of a network request processing device provided by an embodiment of the present application. As Figure 6 shown, the network request processing device 6 of this embodiment includes: a processor 60, a memory 61, and a computer program 62 stored in the memory 61 and executable on the processor 60, such as a network request processing program. When the processor 60 executes the computer program 62, the steps in the above-mentioned various network request processing method embodiments are implemented. Alternatively, when the processor 60 executes the computer program 62, the functions of each module / unit in the above-mentioned device embodiments are implemented.
[0107] Exemplarily, the computer program 62 can be divided into one or more modules / units. The one or more modules / units are stored in the memory 61 and executed by the processor 60 to complete the present application. The one or more modules / units can be a series of computer program instruction segments capable of performing specific functions, and these instruction segments are used to describe the execution process of the computer program 62 in the network request processing device 6.
[0108] The network request processing device may include, but is not limited to, a processor 60 and a memory 61. Those skilled in the art can understand that Figure 6It is merely an example of the network request processing device 6 and does not constitute a limitation on the network request processing device 6. It may include more or fewer components than those shown in the figure, or combine certain components, or different components. For example, the network request processing device may further include input / output devices, network access devices, buses, etc.
[0109] The so-called processor 60 may be a central processing unit (CPU), or may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0110] The memory 61 may be an internal storage unit of the network request processing device 6, such as the hard disk or memory of the network request processing device 6. The memory 61 may also be an external storage device of the network request processing device 6, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the network request processing device 6. Further, the memory 61 may also include both the internal storage unit and the external storage device of the network request processing device 6. The memory 61 is used to store the computer program and other programs and data required by the network request processing device. The memory 61 may also be used to temporarily store the data that has been output or will be output.
[0111] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above-mentioned division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiments can be integrated into a processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of each functional unit and module are only for the convenience of mutual distinction and do not limit the protection scope of this application. The specific working processes of the units and modules in the above system can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated herein.
[0112] In the above embodiments, the descriptions of the various embodiments have their own emphases. For the parts not detailed or recorded in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0113] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, or by a combination of computer software and electronic hardware. Whether these functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0114] In the embodiments provided in this application, it should be understood that the disclosed device / terminal device and method can be implemented in other ways. For example, the device / terminal device embodiments described above are only illustrative. For example, the division of the module or unit is only a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in electrical, mechanical or other forms.
[0115] The unit described as a separated component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit, that is, it may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0116] In addition, in each embodiment of the present application, each functional unit may be integrated into a processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit.
[0117] If the above-mentioned integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it may be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the above-mentioned embodiment methods of the present application can also be completed by hardware related to computer program instructions. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above-mentioned various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disc, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium, etc.
[0118] In addition, the embodiment of the present application also provides a computer program product, which when running on a computer, enables the computer to execute the methods in the above-mentioned various implementation manners.
[0119] The above-mentioned embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A network request processing method, characterized in that: The method comprises: Send a network request and obtain a first observable object generated by the network request; Inserting a global error conversion class into the first observable object through a combination operator to obtain a second observable object, wherein the global error conversion class is used for unified processing according to the type of global errors; Receive response data of the network request, convert and process the response data through the global error conversion class, and obtain the processing result corresponding to the response data, including: receiving the response data of the network request through a base class, the base class including a status code, returned data and a prompt; the global error conversion class converts and processes the response data according to the status code, returned data and prompt included in the base class, and determines whether it is necessary to execute error processing logic based on the checked status code to obtain the processing result corresponding to the response data, including the global error conversion class judging whether the response data is the expected data, if the response data is not the data desired by the network request, converting the returned data into abnormal data through an operator; determining the error code and text description information included in the processing result of the returned data according to the correspondence between the abnormal data and the error code and text description information after the global conversion.
2. The method according to claim 1, characterized in that The global error conversion class converts the response data according to the status code, returned data and prompt included in the base class to obtain a processing result corresponding to the response data, including: Determine the response type corresponding to the status code of the base class according to a predetermined correspondence between the status code and the response type; According to the response type, the response data is converted by the global error conversion class to obtain a processing result corresponding to the response data.
3. The method according to claim 2, characterized in that According to the response type, the response data is converted by the global error conversion class to obtain a processing result corresponding to the response data, including: When the response type is a normal response, transmitting the returned data included in the base class to the downstream; When the response type is an abnormal response, the status code and prompt in the base class are mapped to the globally converted error code and text description information according to a preset mapping relationship to obtain the processing result corresponding to the response data.
4. The method according to claim 2, characterized in that: According to the response type, the response data is converted by the global error conversion class to obtain a processing result corresponding to the response data, including: When the response type is a type to be retried, determining to re-execute the second observable object according to a retry operator.
5. The method according to claim 4, characterized in that The type to be retried includes at least one of a network abnormality type and a server failure type.
6. A network request processing device, characterized in that: The device comprises: A first observable object generating unit, configured to send a network request and obtain a first observable object generated by the network request; an insertion unit, configured to insert a global error conversion class into the first observable object through a combination operator to obtain a second observable object, wherein the global error conversion class is used for unified processing according to the type of the global error; The conversion processing unit is used to receive the response data of the network request, convert the response data through the global error conversion class, and obtain the processing result corresponding to the response data, including: receiving the response data of the network request through a base class, the base class including a status code, returned data and a prompt; the global error conversion class converts the response data according to the status code, returned data and prompt included in the base class, and determines whether it is necessary to execute the error processing logic based on the checked status code to obtain the processing result corresponding to the response data, including the global error conversion class judging whether the response data is the expected data, if the response data is not the data desired by the network request, converting the returned data into abnormal data through an operator; determining the error code and text description information included in the processing result of the returned data according to the correspondence between the abnormal data and the error code and text description information after the global conversion.
7. A network request processing device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the network request processing device implements the method according to any one of claims 1 to 5.
8. A computer program product comprising computer program instructions, characterized in that When the computer program is executed, the method according to any one of claims 1 to 5 is performed.
Citation Information
Patent Citations
Interface calling method and device
CN115495258A
Request error notification message management method and system and application thereof
CN116980323A