ENH: factorize code and enhance error message

2 jobs for !404 with extractroi_modefit in 25 minutes and 21 seconds (queued for 4 seconds)
detached
Status Job ID Name Coverage
  Build
passed #1127
native-build

00:23:21

passed #1128
shark-build

00:25:18