Commit acd018f9 authored by Miguel Rincon's avatar Miguel Rincon

Simplify error message handling in component

parent 88d164a2
...@@ -56,22 +56,19 @@ export default { ...@@ -56,22 +56,19 @@ export default {
return this.$apollo.queries.content.loading; return this.$apollo.queries.content.loading;
}, },
errorMessage() { errorMessage() {
const { message, networkError } = this.error ?? {}; const { message: generalReason, networkError } = this.error ?? {};
let reason = message ?? this.$options.i18n.unknownMessage; const { data } = networkError?.response ?? {};
if (networkError && networkError.response) {
const { data = {} } = networkError.response;
// 400 for a missing ref uses `error`
// 404 for missing file uses `message` // 404 for missing file uses `message`
reason = data.message ?? data.error ?? reason; // 400 for a missing ref uses `error`
} const networkReason = data?.message ?? data?.error;
const reason = networkReason ?? generalReason ?? this.$options.i18n.unknownError;
return sprintf(this.$options.i18n.errorMessageWithReason, { reason }); return sprintf(this.$options.i18n.errorMessageWithReason, { reason });
}, },
}, },
i18n: { i18n: {
unknownMessage: __('Unknown Error'), unknownError: __('Unknown Error'),
errorMessageWithReason: s__('Pipelines|CI file could not be loaded: %{reason}'), errorMessageWithReason: s__('Pipelines|CI file could not be loaded: %{reason}'),
}, },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment