Skip to content

Commit

Permalink
Fix exception handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feyd-Rauth committed Apr 23, 2023
1 parent 93fdbc2 commit b0bb592
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/apiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'

namespace ApiService {
const interval = 1000; // set polling interval to 1 second
const timeout = 12000;
const timeout = 120000;

export async function getToken(username: string, password: string) {
console.log('Authenticating in ARQAN')
Expand Down Expand Up @@ -32,15 +32,16 @@ namespace ApiService {
}
}
)

const task_id = response.data.task_id
console.log("Task id: ", task_id)

response = await axios.get(`http://51.250.88.251:8000/api/tasks/sec-req-extract/${task_id}`, {
headers: {
'Authorization': `Bearer ${token}`,
'accept': 'application/json'
}
});

const startTime = new Date().getTime();
while (response.status === 202 && new Date().getTime() - startTime < timeout) {
await new Promise(resolve => setTimeout(resolve, interval)); // Wait for interval before making another request
Expand All @@ -51,9 +52,8 @@ namespace ApiService {
}
});
}

if (response.status === 202) {
throw new Error('Polling timed out');
throw new Error('Polling timed out. Probably ARQAN is down.');
}

return response.data
Expand Down
6 changes: 0 additions & 6 deletions src/requirement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ import {Stig} from './interfaces'

namespace Requirement {
export async function isSecurity(issue: string, token: string): Promise<boolean> {
console.log('In isSecurity function')
// API call to ARQAN to classify the requirement
let securitySentences = await ApiService.getSecuritySentences(issue, token).then(
(result) => {
return result.requirements
},
(error) => {
throw new Error(
`Received ${error.response.status} status code from ARQAN Classification Service for input: ${issue}.`
)
}
)

Expand Down

0 comments on commit b0bb592

Please sign in to comment.