diff --git a/pkg/modules/migration/csv/csv.go b/pkg/modules/migration/csv/csv.go index 9109dbd92..a9d132f58 100644 --- a/pkg/modules/migration/csv/csv.go +++ b/pkg/modules/migration/csv/csv.go @@ -547,9 +547,7 @@ func parseDate(value, format string) time.Time { // @Failure 500 {object} models.Message "Internal server error" // @Router /migration/csv/migrate [put] func (m *Migrator) Migrate(_ *user.User, _ io.ReaderAt, _ int64) error { - // This will be called with the standard file migrator handler - // The actual configuration will come through the handler - return &migration.ErrNotACSVFile{} // Need config, use MigrateWithConfig instead + return &migration.ErrCSVConfigRequired{} } // MigrateWithConfig imports CSV data into Vikunja with the provided configuration diff --git a/pkg/modules/migration/errors.go b/pkg/modules/migration/errors.go index 6a2a4f780..3129c5da2 100644 --- a/pkg/modules/migration/errors.go +++ b/pkg/modules/migration/errors.go @@ -60,6 +60,28 @@ func (err *ErrFileIsEmpty) HTTPError() web.HTTPError { } } +// ErrCSVConfigRequired represents an error when the CSV migration endpoint +// is called without the required configuration. The CSV migrator requires +// a mapping configuration and must be used via /migration/csv/migrate with +// a config form field. +type ErrCSVConfigRequired struct{} + +func (err *ErrCSVConfigRequired) Error() string { + return "CSV import requires a configuration with column mappings. Use the /migration/csv/detect endpoint to get suggested mappings, then call /migration/csv/migrate with a config form field." +} + +// ErrCodeCSVConfigRequired holds the unique world-error code of this error +const ErrCodeCSVConfigRequired = 14004 + +// HTTPError holds the http error description +func (err *ErrCSVConfigRequired) HTTPError() web.HTTPError { + return web.HTTPError{ + HTTPCode: http.StatusBadRequest, + Code: ErrCodeCSVConfigRequired, + Message: "CSV import requires a configuration with column mappings. Use the /migration/csv/detect endpoint to get suggested mappings, then call /migration/csv/migrate with a config form field.", + } +} + // ErrNotACSVFile represents a "ErrNotACSVFile" kind of error. type ErrNotACSVFile struct{}