Skip to content

Commit

Permalink
remove special handling in JS
Browse files Browse the repository at this point in the history
  • Loading branch information
ichandrasharma committed Feb 11, 2025
1 parent 32e29a5 commit c8d140d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
19 changes: 9 additions & 10 deletions app/assets/javascripts/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,23 +321,22 @@ const API = {
});

if (!response.ok) {
if (response.status === 422 ) {
const data = await response.json();
const errorMessage = data.errors?.[0] || 'Unknown error';
throw new Error(errorMessage);}
else {
const data = await response.text();
this.obj = data;
this.status = response.statusText;
SentryLogger.obj = this.obj;
SentryLogger.status = this.status;
Sentry.captureMessage('saveCourse failed', {
level: 'error',
extra: SentryLogger
});
try {
Sentry.captureMessage('saveCourse failed', {
level: 'error',
extra: SentryLogger
});
} catch (error) {
console.error("Sentry.captureMessage failed:", error);
};
response.responseText = data;
throw response;
}}
}
return response.json();
},

Expand Down
8 changes: 3 additions & 5 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,17 @@ def update
validate
handle_course_announcement(@course.instructors.first)
slug_from_params if should_set_slug?
if @course.update update_params
@course.update update_params
update_courses_wikis
update_course_wiki_namespaces
update_flags
ensure_passcode_set
UpdateCourseWorker.schedule_edits(course: @course, editing_user: current_user)
render json: { course: @course }
else
render json: { errors: @course.errors.full_messages }, status: :unprocessable_entity
end
rescue Course::DuplicateCourseSlugError => e
message = I18n.t('courses.error.duplicate_slug', slug: e.slug)
render json: { errors: [message] }, status: :unprocessable_entity
render json: { errors: e, message: },
status: :unprocessable_entity

rescue Wiki::InvalidWikiError => e
message = I18n.t('courses.error.invalid_wiki', domain: e.domain)
Expand Down
2 changes: 1 addition & 1 deletion app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ class DuplicateCourseSlugError < StandardError
def initialize(slug, msg = 'Duplicate Slug')
@msg = msg
@slug = slug
super('#{msg}: #{slug}')
super(msg)
end

attr_reader :slug
Expand Down

0 comments on commit c8d140d

Please sign in to comment.