vault/ui/tests/helpers/api/error-response.ts
Vault Automation 5807d61ec7
[UI] Ember Data Migration - Control Group Error Handling (#9483) (#9548)
* adds error handling for control groups to api service as post request middleware

* adds waitFor to async middleware in api service to attempt to fix race conditions in tests

Co-authored-by: Jordan Reimer <zofskeez@gmail.com>
2025-10-01 10:58:16 -06:00

25 lines
645 B
TypeScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { ResponseError } from '@hashicorp/vault-client-typescript';
export const getErrorResponse = <T>(error?: T, status?: number) => {
const e = error || {
errors: ['first error', 'second error'],
message: 'there were some errors',
};
// url is readonly on Response so mock it and cast to Response type
const response = {
status: status || 404,
url: `${document.location.origin}/v1/test/error/parsing`,
json: () => Promise.resolve(e),
} as Response;
return new ResponseError({
...response,
clone: () => response,
});
};