decodeRequestErrorMessage function is a utility for extracting meaningful error messages from HTTP response data. It intelligently checks multiple common error message locations and returns the first valid message found, or a default fallback message.ts
import { decodeRequestErrorMessage } from "@arkyn/server";
data (required)anyresponse (required)statusText property representing the HTTP status text.Responsestringtypescript
import { decodeRequestErrorMessage } from "@arkyn/server";// Example with data.messageconst data = { message: "User not found" };const message1 = decodeRequestErrorMessage(data, response);console.log(message1);// Output: "User not found"
data.message: Direct message property on the datadata.error: Error property as a stringdata.error.message: Nested message inside an error objectresponse.statusText: HTTP status text from the Response object"Missing error message"{ message: "..." }{ error: "..." }{ error: { message: "..." } }"Missing error message" to ensure a consistent return type.