Error thrown when an HTTP request fails

This error is thrown by HttpClient methods when the server responds with an error status code (4xx or 5xx).

Example

const http = platform.get(PlatformServiceName.Http);

try {
const data = await http.get('my_addon/data');
} catch (error) {
if (error.name !== 'HttpResponseError') {
throw error;
}

if (error.status === 404) {
console.error('Resource not found');
} else if (error.status >= 500) {
console.error('Server error:', error.status);
}

const body = await error.response.text();
console.error('Response body:', body);
}

Hierarchy

  • Error
    • HttpResponseError

Properties

cause?: unknown
message: string
name: "HttpResponseError"
response: Response

The full Response object from the failed request

Use this to access response headers or read the response body:

const body = await error.response.text();
const contentType = error.response.headers.get('content-type');
stack?: string
status: number

HTTP status code from the failed response