Passed
Push — master ( 519897...4691ad )
by Daniel
01:20
created

scripts/classes/ProcessInputForm/classFetchRemoteData.ts   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 32
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 19
mnd 0
bc 0
fnc 1
dl 0
loc 32
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A classFetchRemoteData.fetchRemoteData 0 20 1
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