kopia lustrzana https://github.com/Stopka/fedicrawl
19 wiersze
728 B
TypeScript
19 wiersze
728 B
TypeScript
import { AxiosResponse } from 'axios'
|
|
import { UnexpectedResponseStatusError } from './UnexpectedResponseStatusError'
|
|
import { UnexpectedContentTypeError } from './UnexpectedContentTypeError'
|
|
|
|
export const assertSuccessJsonResponse = (
|
|
response: AxiosResponse<unknown>
|
|
): void => {
|
|
const expectedStatus = 200
|
|
const actualStatus = response.status
|
|
if (actualStatus !== expectedStatus) {
|
|
throw new UnexpectedResponseStatusError(expectedStatus, actualStatus)
|
|
}
|
|
const expectedContentType = 'application/json'
|
|
const actualContentType = response.headers['content-type']
|
|
if (!actualContentType.startsWith(expectedContentType)) {
|
|
throw new UnexpectedContentTypeError(expectedContentType, actualContentType)
|
|
}
|
|
}
|