Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(() => {
const BadRequestError = getErrorByCode(400);
const error = new BadRequestError('Invalid parameter');
const testMiddleware = createTestMiddleware([
// @ts-ignore
{ action: { type: 'another-action' } },
{
action: sdkActions.get({ uri: '/foo/1' }),
error,
},
{
action: sdkActions.post({
uri: '/foo',
payload: JSON.stringify({ foo: 'bar' }),
}),
response: { foo: 'bar' },
},
]);
static _createResponseError(
{ message = 'Unexpected non-JSON error response', ...rest }: Object,
uri: string,
statusCode: number
): HttpErrorType {
const errorMessage = statusCode === 404 ? `URI not found: ${uri}` : message
let ResponseError = getErrorByCode(statusCode)
if (!ResponseError) ResponseError = getErrorByCode(0)
return new ResponseError(errorMessage, rest)
}
static _createResponseError(
{ message = 'Unexpected non-JSON error response', ...rest }: Object,
uri: string,
statusCode: number
): HttpErrorType {
const errorMessage = statusCode === 404 ? `URI not found: ${uri}` : message
let ResponseError = getErrorByCode(statusCode)
if (!ResponseError) ResponseError = getErrorByCode(0)
return new ResponseError(errorMessage, rest)
}