Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions static/app/actionCreators/dashboards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {defined} from 'sentry/utils';
import {getApiUrl} from 'sentry/utils/api/getApiUrl';
import {TOP_N} from 'sentry/utils/discover/types';
import {fetchMutation} from 'sentry/utils/queryClient';
import {RequestError} from 'sentry/utils/requestError/requestError';
import {getStarredDashboardsQueryKey} from 'sentry/views/dashboards/hooks/useGetStarredDashboards';
import {
DashboardFilter,
Expand All @@ -38,7 +39,8 @@ export function fetchDashboards(
);

promise.catch(response => {
const errorResponse = response?.responseJSON ?? null;
const errorResponse =
response instanceof RequestError ? response?.responseJSON : null;

if (errorResponse) {
const errors = flattenErrors(errorResponse, {});
Expand Down Expand Up @@ -82,7 +84,8 @@ export function createDashboard(
);

promise.catch(response => {
const errorResponse = response?.responseJSON ?? null;
const errorResponse =
response instanceof RequestError ? response?.responseJSON : null;

if (errorResponse) {
const errors = flattenErrors(errorResponse, {});
Expand Down Expand Up @@ -166,8 +169,9 @@ export async function updateDashboardFavorite(
queryKey: getStarredDashboardsQueryKey(organization),
});
addSuccessMessage(isFavorited ? t('Added as favorite') : t('Removed as favorite'));
} catch (response: any) {
const errorResponse = response?.responseJSON ?? null;
} catch (response) {
const errorResponse =
response instanceof RequestError ? response?.responseJSON : null;
if (errorResponse) {
const errors = flattenErrors(errorResponse, {});
addErrorMessage(errors[Object.keys(errors)[0]!]! as string);
Expand All @@ -193,7 +197,8 @@ export function fetchDashboard(
);

promise.catch(response => {
const errorResponse = response?.responseJSON ?? null;
const errorResponse =
response instanceof RequestError ? response?.responseJSON : null;

if (errorResponse) {
const errors = flattenErrors(errorResponse, {});
Expand Down Expand Up @@ -248,7 +253,8 @@ export function updateDashboard(
// that it can be more specific than just "Dashboard updated," but do the
// error-handling here, since it doesn't depend on the caller's context
promise.catch(response => {
const errorResponse = response?.responseJSON ?? null;
const errorResponse =
response instanceof RequestError ? response?.responseJSON : null;

if (errorResponse) {
const errors = flattenErrors(errorResponse, {});
Expand Down Expand Up @@ -281,7 +287,8 @@ export function deleteDashboard(
});

promise.catch(response => {
const errorResponse = response?.responseJSON ?? null;
const errorResponse =
response instanceof RequestError ? response?.responseJSON : null;

if (errorResponse) {
const errors = flattenErrors(errorResponse, {});
Expand Down Expand Up @@ -335,7 +342,8 @@ export function updateDashboardPermissions(
);

promise.catch(response => {
const errorResponse = response?.responseJSON ?? null;
const errorResponse =
response instanceof RequestError ? response?.responseJSON : null;

if (errorResponse) {
const errors = flattenErrors(errorResponse, {});
Expand Down
2 changes: 1 addition & 1 deletion static/app/actionCreators/integrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function applyRepositoryAddComplete(promise: Promise<Repository>) {
});
addSuccessMessage(message);
},
errorData => {
(errorData: any) => {
const text = errorData.responseJSON.errors
? errorData.responseJSON.errors.__all__
: t('Unable to add repository.');
Expand Down
19 changes: 12 additions & 7 deletions static/app/actionCreators/performance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import type {Client} from 'sentry/api';
import {t} from 'sentry/locale';
import {parseLinkHeader} from 'sentry/utils/parseLinkHeader';
import {RequestError} from 'sentry/utils/requestError/requestError';

type KeyTransaction = {
project_id: string;
Expand Down Expand Up @@ -96,13 +97,17 @@ export function toggleKeyTransaction(
promise.then(clearIndicators);

promise.catch(response => {
const responseJSON = response?.responseJSON;
const errorDetails = responseJSON?.detail ?? responseJSON?.non_field_errors;

if (Array.isArray(errorDetails) && errorDetails.length && errorDetails[0]) {
addErrorMessage(errorDetails[0]);
} else {
addErrorMessage(errorDetails ?? t('Unable to update key transaction'));
if (response instanceof RequestError) {
const responseJSON = response?.responseJSON;
const errorDetails = responseJSON?.detail ?? responseJSON?.non_field_errors;

if (Array.isArray(errorDetails) && errorDetails.length && errorDetails[0]) {
addErrorMessage(errorDetails[0]);
} else if (typeof errorDetails === 'string') {
addErrorMessage(errorDetails);
} else {
addErrorMessage(t('Unable to update key transaction'));
}
}
});

Expand Down
9 changes: 5 additions & 4 deletions static/app/actionCreators/projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {ProjectsStore} from 'sentry/stores/projectsStore';
import type {Team} from 'sentry/types/organization';
import type {Project} from 'sentry/types/project';
import {apiOptions} from 'sentry/utils/api/apiOptions';
import type {RequestError} from 'sentry/utils/requestError/requestError';
import {useApi} from 'sentry/utils/useApi';

type UpdateParams = {
Expand All @@ -38,7 +39,7 @@ export function update(api: Client, params: UpdateParams) {
ProjectsStore.onUpdateSuccess(data);
return data;
},
err => {
(err: Error) => {
ProjectsStatsStore.onUpdateError(err, params.projectId);
throw err;
}
Expand Down Expand Up @@ -138,11 +139,11 @@ export function transferProject(
})
);
},
err => {
(err: RequestError) => {
let message = '';
// Handle errors with known failures
if (err.status >= 400 && err.status < 500 && err.responseJSON) {
message = err.responseJSON?.detail;
if (err.status && err.status >= 400 && err.status < 500 && err.responseJSON) {
message = err.responseJSON.detail as string;
}

if (message) {
Expand Down
20 changes: 18 additions & 2 deletions static/app/actionCreators/release.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import type {Client} from 'sentry/api';
import {t} from 'sentry/locale';
import {ReleaseStatus} from 'sentry/types/release';
import {RequestError} from 'sentry/utils/requestError/requestError';

type ParamsGet = {
orgSlug: string;
Expand All @@ -31,7 +32,14 @@ export function archiveRelease(api: Client, params: ParamsGet) {
addSuccessMessage(t('Release was successfully archived.'));
})
.catch(error => {
addErrorMessage(error.responseJSON?.detail ?? t('Release could not be archived.'));
if (
error instanceof RequestError &&
typeof error.responseJSON?.detail === 'string'
) {
addErrorMessage(error.responseJSON?.detail);
} else {
addErrorMessage(t('Release could not be archived.'));
}
throw error;
});
}
Expand All @@ -54,7 +62,15 @@ export function restoreRelease(api: Client, params: ParamsGet) {
addSuccessMessage(t('Release was successfully restored.'));
})
.catch(error => {
addErrorMessage(error.responseJSON?.detail ?? t('Release could not be restored.'));
if (
error instanceof RequestError &&
typeof error.responseJSON?.detail === 'string'
) {
addErrorMessage(error.responseJSON?.detail);
} else {
addErrorMessage(t('Release could not be restored.'));
}

throw error;
});
}
2 changes: 1 addition & 1 deletion static/app/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ export class Client {
// Not related to errors in responses
}
)
.catch(error => {
.catch((error: Error) => {
// eslint-disable-next-line no-console
console.error(error);

Expand Down
4 changes: 2 additions & 2 deletions static/app/components/core/select/async.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SelectAsyncControl<TData = unknown> extends Component<
api: Client | null;
cache: Record<string, unknown>;

doQuery = debounce((cb: (...args: [RequestError] | [null, TData]) => void) => {
doQuery = debounce((cb: (...args: [Error] | [null, TData]) => void) => {
const {url, onQuery} = this.props;
const {query} = this.state;

Expand All @@ -79,7 +79,7 @@ class SelectAsyncControl<TData = unknown> extends Component<
})
.then(
data => cb(null, data),
err => cb(err)
(err: Error) => cb(err)
);
}, 250);

Expand Down
18 changes: 12 additions & 6 deletions static/app/components/exports/useDataExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {ResponseMeta} from 'sentry/api';
import {t} from 'sentry/locale';
import {getApiUrl} from 'sentry/utils/api/getApiUrl';
import {downloadFromHref} from 'sentry/utils/downloadFromHref';
import {RequestError} from 'sentry/utils/requestError/requestError';
import {useApi} from 'sentry/utils/useApi';
import {useOrganization} from 'sentry/utils/useOrganization';
import {createLogDownloadFilename} from 'sentry/views/explore/logs/createLogDownloadFilename';
Expand Down Expand Up @@ -112,13 +113,18 @@ export function useDataExport({
if (unmountedRef?.current) {
return;
}
const message =
error?.responseJSON?.detail ??
t(
"We tried our hardest, but we couldn't export your data. Give it another go."
if (
error instanceof RequestError &&
typeof error.responseJSON?.detail === 'string'
) {
addErrorMessage(error.responseJSON.detail);
} else {
addErrorMessage(
t(
"We tried our hardest, but we couldn't export your data. Give it another go."
)
);

addErrorMessage(message);
}
inProgressCallback?.(false);
});

Expand Down
4 changes: 2 additions & 2 deletions static/app/components/forms/model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ export class FormModel {
this.options.onSubmitSuccess(resp, this);
}
})
.catch(resp => {
.catch((resp: any) => {
// should we revert field value to last known state?
saveSnapshot = null;
if (this.options.resetOnError) {
Expand Down Expand Up @@ -648,7 +648,7 @@ export class FormModel {

return data;
})
.catch(resp => {
.catch((resp: any) => {
// should we revert field value to last known state?
saveSnapshot = null;

Expand Down
2 changes: 1 addition & 1 deletion static/app/components/selectMembers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class SelectMembers extends Component<Props, State> {
})
.then(
data => cb(null, data),
err => cb(err)
err => cb(err as Error)
);
},
250
Expand Down
10 changes: 10 additions & 0 deletions static/app/types/promise.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
interface Promise<T> {
then<TFul = T, TRej = never>(
onfulfilled?: ((value: T) => TFul | PromiseLike<TFul>) | null,
onrejected?: ((reason: unknown) => TRej | PromiseLike<TRej>) | null
): Promise<TFul | TRej>;
Comment thread
cursor[bot] marked this conversation as resolved.

catch<TRej = never>(
onrejected?: ((reason: unknown) => TRej | PromiseLike<TRej>) | null
): Promise<T | TRej>;
}
2 changes: 1 addition & 1 deletion static/app/views/alerts/rules/issue/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ class IssueRuleEditor extends DeprecatedAsyncComponent<Props, State> {
success: true,
});
})
.catch(error => {
.catch((error: any) => {
addErrorMessage(tn('Notification failed', 'Notifications failed', actions));
this.setState({detailedError: error.responseJSON || null});
trackAnalytics('edit_alert_rule.notification_test', {
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/dashboards/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ class DashboardDetail extends Component<Props, State> {
Sentry.captureMessage('Generated dashboard failed to save', {
extra: {
dashboard_title: newModifiedDashboard.title,
error_message: error?.message,
error_message: error instanceof Error ? error.message : undefined,
},
});
});
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/dashboards/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export function getWidgetReleasesUrl(
}

export function flattenErrors(
data: ValidationError | string,
data: Record<string, unknown> | string,
update: FlatValidationError
): FlatValidationError {
if (typeof data === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/discover/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class Table extends PureComponent<TableProps, TableState> {
setSplitDecision?.(splitDecision);
}
})
.catch(err => {
.catch((err: any) => {
metric.measure({
name: 'app.api.discover-query',
start: `discover-events-start-${apiPayload.query}`,
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/explore/profiling/profilesProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function TransactionProfileProvider({
setProfile({type: 'resolved', data: p});
})
.catch(err => {
const message = err.toString();
const message = String(err);

setProfile({type: 'errored', error: message});
Sentry.captureException(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {Organization} from 'sentry/types/organization';
import type {Project} from 'sentry/types/project';
import {defined} from 'sentry/utils';
import type {EventView} from 'sentry/utils/discover/eventView';
import {RequestError} from 'sentry/utils/requestError/requestError';
import {withApi} from 'sentry/utils/withApi';
import {withProjects} from 'sentry/utils/withProjects';

Expand Down Expand Up @@ -81,8 +82,9 @@ function TransactionThresholdButton({
})
.catch(err => {
setLoadingThreshold(false);
const errorMessage = err.responseJSON?.threshold ?? null;
addErrorMessage(errorMessage);
const errorMessage =
err instanceof RequestError ? err.responseJSON?.threshold : null;
addErrorMessage(errorMessage as string);
});
});
}, [api, project, organization.slug, transactionName]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {Organization} from 'sentry/types/organization';
import type {Project} from 'sentry/types/project';
import {defined} from 'sentry/utils';
import type {EventView} from 'sentry/utils/discover/eventView';
import {RequestError} from 'sentry/utils/requestError/requestError';
import {withApi} from 'sentry/utils/withApi';
import {withProjects} from 'sentry/utils/withProjects';

Expand Down Expand Up @@ -91,11 +92,13 @@ function TransactionThresholdModal({
})
.catch(err => {
let errorMessage =
err.responseJSON?.threshold ?? err.responseJSON?.non_field_errors ?? null;
err instanceof RequestError
? (err.responseJSON?.threshold ?? err.responseJSON?.non_field_errors)
: null;
if (Array.isArray(errorMessage)) {
errorMessage = errorMessage[0];
}
addErrorMessage(errorMessage);
addErrorMessage(errorMessage as string);
});
};

Expand Down Expand Up @@ -139,8 +142,9 @@ function TransactionThresholdModal({
});
})
.catch(err => {
const errorMessage = err.responseJSON?.threshold ?? null;
addErrorMessage(errorMessage);
const errorMessage =
err instanceof RequestError ? err.responseJSON?.threshold : null;
addErrorMessage(errorMessage as string);
});
};

Expand Down
Loading
Loading