Skip to content

API error responses without statusCode are considered successful #338

@boxmein

Description

@boxmein

It seems that API responses that have a HTTP status of 4xx or 5xx, but don't include a statusCode field in the JSON body, are considered success responses.

Both responseIsError and responseIsLegacyError return false when statusCode is missing.

function responseIsLegacyError(
response: ApiResponse,
): response is LegacyErrorResponse {
return (
response.statusCode &&
Math.floor(response.statusCode / 100) !== 2 &&
!Object.prototype.hasOwnProperty.call(response, 'error')
);
}
/**
* Returns true if an ApiResponse is an ClientErrorResponse response, usable as a type guard.
* @param response an ApiResponse to narrow down
* @returns true if the ApiResponse is an ClientErrorResponse, false if it is a SuccessResponse
* @hidden
*/
function responseIsClientError(
response: ApiResponse,
): response is ClientErrorResponse {
return (
response.statusCode &&
Math.floor(response.statusCode / 100) === 4 &&
Object.prototype.hasOwnProperty.call(response, 'error')
);
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions