next-request.ts


Overview

The next-request.ts file serves as a centralized HTTP client utility for making API requests in the application. It uses the popular Axios library to create and configure an HTTP client instance that handles:

This utility abstracts away repetitive request logic and provides consistent error handling and localization support, making it easier to interact with backend APIs throughout the application.


Detailed Explanations

Constants and Types

FAILED_TO_FETCH

RetcodeMessage

ResultCode


Functions

errorHandler

const errorHandler = (error: { response: Response; message: string; }): Response

Axios Instance: request

const request = axios.create({
  timeout: 300000,
});

Exported Utility Functions

get

export const get = (url: string) => request.get(url);

post

export const post = (url: string, body: any) => request.post(url, { data: body });

drop and put


Important Implementation Details


Interaction with Other Parts of the Application

This file is a foundational utility likely imported by various service or API modules across the application to perform HTTP requests consistently.


Visual Diagram

flowchart TD
  A[Request Function Call] --> B[request Interceptors]
  B --> |Request Interceptor| C[convert keys to snake_case]
  C --> D{skipToken?}
  D -- No --> E[Add Authorization Header]
  D -- Yes --> E
  E --> F[Send HTTP Request]
  F --> G[Response Interceptor]
  G --> H{Response Status}
  H -- 413/504 --> I[Show error message]
  H -- Other --> J{Response Type}
  J -- blob --> K[Return response directly]
  J -- json --> L{Response Data Code}
  L -- 100 --> M[Show error message]
  L -- 401 --> N[Show notification, logout, redirect]
  L -- other non-zero --> O[Show notification]
  L -- 0 --> P[Return response]
  G -- Error --> Q[Call errorHandler, reject]

Summary

The next-request.ts file is a robust HTTP client abstraction built on Axios designed to facilitate API communication in the application. It focuses on:

This utility promotes maintainable, clean, and secure network communication across the application.