Skip to content
Snippets Groups Projects
Commit 1cda1ec5 authored by Gregor Schulz's avatar Gregor Schulz
Browse files

improve logging

parent b613d351
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@ describe('GeoAPIClient', () => {
beforeEach(() => {
restore()
client = new GeoApiClient('http://holi.geo.gedoenz.doesntexist')
client = new GeoApiClient('http://holi.geo.gedoenz.doesntexist', console)
})
it('throws error for invalid response when fetching geometry', async () => {
......
import { GeoAPIResponse, GeolocationCoordinates } from './GeoApiClient.types.ts'
import { ResolvesCity } from '../../usecases/dependencies/ResolvesCity.ts'
import { ResolvesCoordinates } from '../../usecases/dependencies/ResolvesCoordinates.ts'
import { Logs } from '../../usecases/dependencies/Logs.ts'
import { GraphQLError } from '../../deps.ts'
export class GeoApiClient implements ResolvesCoordinates, ResolvesCity {
constructor(private readonly endpointUrl: string) {
constructor(private readonly endpointUrl: string, private readonly logger: Logs) {
}
async resolveCoordinates(
......@@ -14,7 +16,7 @@ export class GeoApiClient implements ResolvesCoordinates, ResolvesCity {
if (lat && lon) {
return { lat, lon }
} else {
throw new Deno.errors.NotCapable(
throw new GraphQLError(
`Resolution of lat/lon failed (no data in response for geolocationId=${geolocationId})`,
)
}
......@@ -28,7 +30,7 @@ export class GeoApiClient implements ResolvesCoordinates, ResolvesCity {
if (city) {
return city
} else {
throw new Deno.errors.NotCapable(
throw new GraphQLError(
`Resolution of city name failed (no data in response for geolocationId=${geolocationId})`,
)
}
......@@ -46,6 +48,14 @@ export class GeoApiClient implements ResolvesCoordinates, ResolvesCity {
},
'method': 'POST',
})
return await response.json() as GeoAPIResponse
const body = await response.json()
if (Object.hasOwn(body, 'errors')) {
this.logger.error(body.errors)
throw new GraphQLError("Can't fetchPlaceDetails for geolocationId " + geolocationId)
}
return body as GeoAPIResponse
}
}
......@@ -3,7 +3,7 @@ import { FetchesJasdActivities } from '../../usecases/dependencies/FetchesJasdAc
import { Logs } from '../../usecases/dependencies/Logs.ts'
import { FetchesJasdActivity } from '../../usecases/dependencies/FetchesJasdActivity.ts'
import { logger } from '../Logger.ts'
import NotFound = Deno.errors.NotFound
import { GraphQLError } from 'npm:graphql@16.10.0'
export class JasdGateway implements FetchesJasdActivities, FetchesJasdActivity {
private readonly APP_API_BASE_URL_V1 = 'https://gemeinschaftswerk-nachhaltigkeit.de/app/api/v1'
......@@ -48,7 +48,7 @@ export class JasdGateway implements FetchesJasdActivities, FetchesJasdActivity {
try {
const json = await response.json() as Activity
if (!json) {
throw new NotFound('Not found')
throw new GraphQLError('Not found')
}
return json
......
import { describe, it } from '@std/testing/bdd'
import { assertEquals, assertRejects } from '@std/assert'
import NotFound = Deno.errors.NotFound
import { QueryEvent } from './QueryEvent.ts'
import { LocalTimedActivity } from '../adapters/jasd/tests/fixtures.ts'
import { Activity } from '../adapters/jasd/types/appapi.dto.types.ts'
import { GraphQLError } from 'npm:graphql@16.10.0'
describe('QueryEvent', () => {
it('throws when no event can be fetched', () => {
const jasdGatewayMock = {
fetchActivity() {
return Promise.reject(new Deno.errors.NotFound())
return Promise.reject(new GraphQLError(''))
},
}
const sut = new QueryEvent(jasdGatewayMock, console)
assertRejects(() => sut.execute({ id: 'iDoesNotExist' }), NotFound)
assertRejects(() => sut.execute({ id: 'iDoesNotExist' }), GraphQLError)
})
it('works for a jasd api response', async () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment