Skip to content

Commit

Permalink
Changed: enhanced ApiRepository error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
GPortas committed Mar 6, 2024
1 parent dc12a7a commit 40836d2
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
6 changes: 6 additions & 0 deletions jest.config.functional.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import config from './jest.config'

config.modulePathIgnorePatterns = ['<rootDir>/test/unit', '<rootDir>/test/integration']
console.log('RUNNING FUNCTIONAL TESTS')

export default config
2 changes: 1 addition & 1 deletion jest.config.integration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from './jest.config'

config.modulePathIgnorePatterns = ['<rootDir>/test/unit']
config.modulePathIgnorePatterns = ['<rootDir>/test/unit', '<rootDir>/test/functional']
console.log('RUNNING INTEGRATION TESTS')

export default config
2 changes: 1 addition & 1 deletion jest.config.unit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from './jest.config'

config.modulePathIgnorePatterns = ['<rootDir>/test/integration']
config.modulePathIgnorePatterns = ['<rootDir>/test/integration', '<rootDir>/test/functional']
delete config.globalSetup
delete config.testTimeout
console.log('RUNNING UNIT TESTS')
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"test": "jest -c jest.config.ts",
"test:unit": "jest -c jest.config.unit.ts",
"test:integration": "jest -c jest.config.integration.ts",
"test:functional": "jest -c jest.config.functional.ts",
"test:coverage": "jest --coverage -c jest.config.ts",
"test:coverage:check": "jest --coverage --ci --config jest.config.ts",
"lint": "npm run lint:eslint && npm run lint:prettier",
Expand Down
20 changes: 10 additions & 10 deletions src/core/infra/repositories/ApiRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ export abstract class ApiRepository {
.get(this.buildRequestUrl(apiEndpoint), this.buildRequestConfig(authRequired, queryParams))
.then((response) => response)
.catch((error) => {
throw new ReadError(
`[${error.response.status}]${
error.response.data ? ` ${error.response.data.message}` : ''
}`
)
throw new ReadError(this.buildErrorMessage(error))
})
}

Expand All @@ -34,11 +30,7 @@ export abstract class ApiRepository {
)
.then((response) => response)
.catch((error) => {
throw new WriteError(
`[${error.response.status}]${
error.response.data ? ` ${error.response.data.message}` : ''
}`
)
throw new WriteError(this.buildErrorMessage(error))
})
}

Expand Down Expand Up @@ -87,4 +79,12 @@ export abstract class ApiRepository {
private buildRequestUrl(apiEndpoint: string): string {
return `${ApiConfig.dataverseApiUrl}${apiEndpoint}`
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private buildErrorMessage(error: any): string {
const status =
error.response && error.response.status ? error.response.status : 'unknown error status'
const message = error.response && error.response.data ? ` ${error.response.data.message}` : ''
return `[${status}]${message}`
}
}
5 changes: 5 additions & 0 deletions test/functional/datasets/CreateDataset.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//import { createDataset, CreatedDatasetIdentifiers } from '../../../src/datasets'

describe('execute', () => {
test('should create new dataset', async () => {})

Check warning on line 4 in test/functional/datasets/CreateDataset.test.ts

View workflow job for this annotation

GitHub Actions / lint

Test has no assertions
})
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"test",
"jest.config.integration.ts",
"jest.config.js",
"jest.config.unit.ts"
"jest.config.unit.ts",
"jest.config.functional.ts"
],
"exclude": ["node_modules", "dist"]
}

0 comments on commit 40836d2

Please sign in to comment.