project.tsx 875 B

123456789101112131415161718192021222324252627282930
  1. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  2. import {Client} from 'sentry/api';
  3. import {t} from 'sentry/locale';
  4. import ProjectsStore from 'sentry/stores/projectsStore';
  5. import {Project} from 'sentry/types';
  6. import {handleXhrErrorResponse} from 'sentry/utils/handleXhrErrorResponse';
  7. import RequestError from 'sentry/utils/requestError/requestError';
  8. /**
  9. * Fetches a project's details
  10. */
  11. export function fetchProjectDetails({
  12. api,
  13. orgSlug,
  14. projSlug,
  15. }: {
  16. api: Client;
  17. orgSlug: string;
  18. projSlug: string;
  19. }): Promise<Project> {
  20. const promise = api.requestPromise(`/projects/${orgSlug}/${projSlug}/`);
  21. promise.then(ProjectsStore.onUpdateSuccess).catch((error: RequestError) => {
  22. const message = t('Unable to fetch project details');
  23. handleXhrErrorResponse(message, error);
  24. addErrorMessage(message);
  25. });
  26. return promise;
  27. }