add error catches

This commit is contained in:
Kfir Dayan 2023-04-25 02:37:40 +03:00
parent 5f2fe8c77d
commit e52c9b5493
3 changed files with 86 additions and 13 deletions

View file

@ -1 +1,5 @@
GEOCODING_API_KEY='your_api_key'
NODE_ENV=development
PGUSER=admin
PGHOST=admin

View file

@ -17,3 +17,68 @@ install pg MacOS -
Start Postgres -
brew services start postgresql
knex for migration files
npx knex migrate:make create_addresses_table
npx knex migrate:latest
npx knex migrate:rollback
npx knex seed:make 01_addresses
npx knex seed:run
npx knex migrate:make create_addresses_table
npx knex migrate:latest
npx knex migrate:rollback
npx knex seed:make 01_addresses
npx knex seed:run
npx knex migrate:make create_addresses_table
npx knex migrate:latest
npx knex migrate:rollback
npx knex seed:make 01_addresses
npx knex seed:run
npx knex migrate:make create_addresses_table
npx knex migrate:latest
npx knex migrate:rollback
npx knex seed:make 01_addresses
npx knex seed:run
npx knex migrate:make create_addresses_table
npx knex migrate:latest
npx knex migrate:rollback
npx knex seed:make 01_addresses
npx knex seed:run
npx knex migrate:make create_addresses_table
npx knex migrate:latest
npx knex migrate:rollback
npx knex seed:make 01_addresses
npx knex seed:run
npx knex migrate:make create_addresses_table
npx knex migrate:latest
npx knex migrate:rollback
npx knex seed:make 01_addresses
npx knex seed:run
npx knex migrate:make create_addresses_table
npx knex migrate:latest
npx knex migrate:rollback
npx knex seed:make 01_addresses
npx knex seed:run
npx knex migrate:make create_addresses_table
npx knex migrate:latest
npx knex migrate:rollback
npx knex seed:make 01_addresses
npx knex seed:run

View file

@ -9,6 +9,7 @@ const GEOCODING_API_KEY = process.env.GEOCODING_API_KEY;
// will return at least - street, line1, line2, country, postcode
export const resolveAddress = async (searchTerm: string): Promise<Address> => {
try {
const response = await axios.get(`https://api.geoapify.com/v1/geocode/search?text=${searchTerm}&format=json&apiKey=${GEOCODING_API_KEY}`);
if (response.data.results.length > 0) {
const result = response.data.results[0];
@ -22,4 +23,7 @@ export const resolveAddress = async (searchTerm: string): Promise<Address> => {
} else {
throw new Error('No results found');
}
} catch (error) {
throw error.message;
}
};