Skip to content

Commit 3576349

Browse files
committed
fix: return model errors instead of raw exception in regenerate_join_code
Returning e.message leaked the 'Validation failed: …' prefix and inconsistent shape vs. the other actions in this controller, which return a clean { error: … } payload. Use the model's full_messages joined to a sentence to keep the API contract uniform.
1 parent 3dbd8c8 commit 3576349

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

app/controllers/api/school_classes_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def regenerate_join_code
8585
@school_class.regenerate_join_code!
8686
@school_class_with_teachers = @school_class.with_teachers
8787
render :show, formats: [:json], status: :ok
88-
rescue ActiveRecord::RecordInvalid => e
89-
render json: { error: e.message }, status: :unprocessable_content
88+
rescue ActiveRecord::RecordInvalid
89+
render json: { error: @school_class.errors.full_messages.to_sentence }, status: :unprocessable_content
9090
end
9191

9292
private

0 commit comments

Comments
 (0)