mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-03-09 07:13:35 -05:00
fix(migration): improve error message when CSV config is missing
Replace the misleading ErrNotACSVFile with a new ErrCSVConfigRequired error in the Migrate method. The new error explains that the CSV migrator requires a column mapping configuration and points to the correct /migration/csv/detect endpoint.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user