-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// URLResponse+Extensions.swift | ||
// Counters | ||
// | ||
// Created by Fabio Cezar Salata on 28/07/21. | ||
// | ||
|
||
import Foundation | ||
|
||
enum ValidationStatus { | ||
case informational // 100 | ||
case success // 200 | ||
case redirection // 300 | ||
case clientError // 400 | ||
case serverError // 500 | ||
case unknown | ||
} | ||
|
||
extension URLResponse { | ||
var validationStatus: ValidationStatus { | ||
if let httpResponse = self as? HTTPURLResponse { | ||
let statusCode = httpResponse.statusCode | ||
switch statusCode { | ||
case 0...199: | ||
return .informational | ||
case 200...299: | ||
return .success | ||
case 300...399: | ||
return .redirection | ||
case 400...499: | ||
return .clientError | ||
case 500...599: | ||
return .serverError | ||
default: | ||
return .unknown | ||
} | ||
} else { | ||
return .unknown | ||
} | ||
} | ||
} |