Skip to content

Commit

Permalink
Improve error handling (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet authored Nov 8, 2024
1 parent ded31a3 commit 1535a79
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

/**
* Exception thrown when an Authority does not have a valid URL.
* The URL is a mandatory field of a GTFS Agency.
*/
public class MissingAuthorityUrlException extends GtfsExportException {
public class InvalidAuthorityUrlException extends GtfsExportException {

public MissingAuthorityUrlException(String message) {
public InvalidAuthorityUrlException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.entur.netex.gtfs.export.producer;

import org.entur.netex.gtfs.export.exception.InvalidAuthorityUrlException;
import org.entur.netex.gtfs.export.repository.NetexDatasetRepository;
import org.onebusaway.gtfs.model.Agency;
import org.rutebanken.netex.model.Authority;
Expand Down Expand Up @@ -55,20 +56,19 @@ public Agency produce(Authority authority) {
if (isValidGtfsUrl(url)) {
agency.setUrl(url);
} else {
LOGGER.warn(
"Invalid URL format {} for authority {}",
url,
authority.getId()
throw new InvalidAuthorityUrlException(
"Invalid URL for authority " + authority.getId()
);
}
} else {
LOGGER.warn("Missing URL for authority {}", authority.getId());
throw new InvalidAuthorityUrlException(
"Missing URL for authority " + authority.getId()
);
}
agency.setPhone(contactDetails.getPhone());
} else {
LOGGER.warn(
"Missing Contact details for authority {}",
authority.getId()
throw new InvalidAuthorityUrlException(
"Missing Contact details for authority " + authority.getId()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.entur.netex.gtfs.export.exception.GtfsExportException;
import org.entur.netex.gtfs.export.exception.GtfsSerializationException;
import org.onebusaway.csv_entities.exceptions.CsvException;
import org.onebusaway.gtfs.model.Route;
import org.onebusaway.gtfs.model.StopTime;
import org.onebusaway.gtfs.model.Trip;
Expand Down Expand Up @@ -67,6 +69,11 @@ public InputStream writeGtfs(GtfsDao gtfsDao) {
writer.setOutputLocation(outputFile);
writer.run(gtfsDao);
return createDeleteOnCloseInputStream(outputFile);
} catch (CsvException csve) {
throw new GtfsExportException(
"Cannot produce a valid GTFS dataset",
csve
);
} catch (IOException e) {
throw new GtfsSerializationException(
"Error while saving the GTFS dataset",
Expand Down

0 comments on commit 1535a79

Please sign in to comment.