Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 32 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | // Class imports |
||
2 | import classShowHideElements from './classShowHideElements'; |
||
3 | import classErrorHandler from '../ErrorHandler/classErrorHandler'; |
||
4 | |||
5 | /** |
||
6 | * Class responsible for fetching the remote data |
||
7 | */ |
||
8 | export default class classFetchRemoteData { |
||
9 | /** |
||
10 | * The method responsible for fetching the remote data |
||
11 | * @returns Promise Returns a promise with the data fetched. Implements a catch that hides elements and shows error message if there is an error |
||
12 | */ |
||
13 | static fetchRemoteData() { |
||
14 | const bilInformasjon = (<HTMLInputElement>( |
||
15 | window.document.getElementById('bilinformasjon') |
||
16 | )).value; |
||
17 | const regNummer = `${process.env.API_URL}${bilInformasjon}`; |
||
18 | |||
19 | return fetch(regNummer) |
||
20 | .then(async (response) => { |
||
21 | const bilResponse = await response.text(); |
||
22 | const bilData = JSON.parse(bilResponse); |
||
23 | return bilData; |
||
24 | }) |
||
25 | .catch(function (error) { |
||
26 | // Hide elements if we have an error |
||
27 | classShowHideElements.hideElements(); |
||
28 | classErrorHandler.showErrorFetchingRegNr(); |
||
29 | }); |
||
30 | } |
||
31 | } |
||
32 |