[client] refresh token on 401 and 403
This commit is contained in:
		
							parent
							
								
									4cc78fb657
								
							
						
					
					
						commit
						97b411e0c5
					
				
					 1 changed files with 20 additions and 0 deletions
				
			
		| 
						 | 
					@ -55,6 +55,11 @@ class ApiClient {
 | 
				
			||||||
      headers: headers(forGet: true),
 | 
					      headers: headers(forGet: true),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (response.statusCode == 401 || response.statusCode == 403) {
 | 
				
			||||||
 | 
					      await refresh();
 | 
				
			||||||
 | 
					      return await get(path);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (response.statusCode != 200) {
 | 
					    if (response.statusCode != 200) {
 | 
				
			||||||
      throw Exception('Response returned status code: ${response.statusCode}');
 | 
					      throw Exception('Response returned status code: ${response.statusCode}');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -69,6 +74,11 @@ class ApiClient {
 | 
				
			||||||
      headers: headers(forLogin: forLogin),
 | 
					      headers: headers(forLogin: forLogin),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (response.statusCode == 401 || response.statusCode == 403) {
 | 
				
			||||||
 | 
					      await refresh();
 | 
				
			||||||
 | 
					      return await post(path, body, forLogin: forLogin);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (response.statusCode != 200) {
 | 
					    if (response.statusCode != 200) {
 | 
				
			||||||
      throw Exception('Response returned status code: ${response.statusCode}');
 | 
					      throw Exception('Response returned status code: ${response.statusCode}');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -83,6 +93,11 @@ class ApiClient {
 | 
				
			||||||
      headers: headers(),
 | 
					      headers: headers(),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (response.statusCode == 401 || response.statusCode == 403) {
 | 
				
			||||||
 | 
					      await refresh();
 | 
				
			||||||
 | 
					      return await delete(path);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (response.statusCode != 200) {
 | 
					    if (response.statusCode != 200) {
 | 
				
			||||||
      throw Exception('Response returned status code: ${response.statusCode}');
 | 
					      throw Exception('Response returned status code: ${response.statusCode}');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -95,6 +110,11 @@ class ApiClient {
 | 
				
			||||||
      headers: headers(),
 | 
					      headers: headers(),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (response.statusCode == 401 || response.statusCode == 403) {
 | 
				
			||||||
 | 
					      await refresh();
 | 
				
			||||||
 | 
					      return await patch(path, body);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (response.statusCode != 200) {
 | 
					    if (response.statusCode != 200) {
 | 
				
			||||||
      throw Exception('Response returned status code: ${response.statusCode}');
 | 
					      throw Exception('Response returned status code: ${response.statusCode}');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue