Skip to content

RequestError ​

The unified error structure rejected on failure by all APIs (request(), the shortcut methods, instance methods), mirroring AxiosError: a code error-code system + config / response attachments + the native errCode preserved.

uts
export type RequestError = {
	/** Library error code (literal union) */
	code: RequestErrorCode
	/** Fixed subject, handy for business-side filtering */
	errSubject: string
	/** Error description */
	errMsg: string
	/** Native fail errCode passed through as-is (5 / 600003 / …); null for library errors */
	nativeErrCode: number | null
	/** HTTP status code (for BAD_REQUEST / BAD_RESPONSE) */
	statusCode: number | null
	/** The final merged configuration that issued this request (mirrors axios error.config) */
	config: RequestConfig | null
	/** Carries the raw response on HTTP errors (including the 4xx/5xx body, mirrors axios error.response) */
	response: ResponseAny | null
}

Fields ​

NameTypeDescription
codeRequestErrorCodeLibrary error code, classified deterministically; the single basis for business branching
errSubjectstringFixed 'unix-request' (entry constant REQUEST_ERR_SUBJECT), so business code can filter this library's errors
errMsgstringError description. Passes through the native errMsg on native failures; on cancellation reads like 请求已取消:页面卸载 ("request canceled: page unloaded")
nativeErrCodenumber | nullThe native fail errCode passed through as-is, unmapped (e.g. timeout 5, network interruption 600003); null for library errors
statusCodenumber | nullHTTP status code, present only for ERR_BAD_REQUEST / ERR_BAD_RESPONSE
configRequestConfig | nullThe final merged configuration that issued this request (send snapshot), for replaying requests or log instrumentation
responseResponseAny | nullCarries the raw response on HTTP errors (including the 4xx/5xx body), present only for ERR_BAD_REQUEST / ERR_BAD_RESPONSE

Error Classification at a Glance ​

StageClassificationnativeErrCodestatusCoderesponse
Pre-send parameter check (empty url)ERR_PARAMnullnullnull
Pre-send configuration check (relative path without baseURL)ERR_CONFIGnullnullnull
Cancellation (canceled before send / aborted in flight)ERR_CANCELEDnullnullnull
Native timeout (errCode 5)ERR_TIMEOUT5nullnull
Native network error (600003 / 600010)ERR_NETWORKoriginal valuenullnull
HTTP 4xx (validateStatus failed)ERR_BAD_REQUESTnullthe 4xx valueraw response attached
HTTP 5xx (validateStatus failed)ERR_BAD_RESPONSEnullthe 5xx valueraw response attached
Other native failures (1000 / 100001–100003 / 600008 / 600009 / 602001, etc.) and library-level interceptor / transform exceptionsERR_NATIVEoriginal value or nullnullnull

Second use of errSubject

The interceptor onRejected return-value detection also relies on this contract: a returned object with errSubject === 'unix-request' is treated as a RequestError (error swap), otherwise as a ResponseResult (recovery). Use the library's error structure when swapping errors; see Interceptor API.

Examples ​

uts
import { request } from '@/uni_modules/ux-request'
import type { RequestError } from '@/uni_modules/ux-request'

request<UTSJSONObject>({ url: '/api/missing' }).catch((err) => {
	const e = err as RequestError
	console.log(e.errSubject)     // unix-request
	console.log(e.code)           // ERR_BAD_REQUEST
	console.log(e.statusCode)     // 404
	console.log(e.response?.data) // the error body returned by the server
	console.log(e.config.url)     // the full URL actually sent
})

Released under the MIT License.