kopia lustrzana https://github.com/Stopka/fedicrawl
17 wiersze
724 B
TypeScript
17 wiersze
724 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)
|
|
}
|
|
}
|