Skip to content

Commit 688093c

Browse files
committed
chore: error for oauth
1 parent dd412d9 commit 688093c

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/app_error/src/lib.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ pub enum AppError {
3333
#[error("{0}")]
3434
OAuthError(String),
3535

36+
#[error("{0}")]
37+
BadRequest(String),
38+
39+
#[error("{0}")]
40+
UserAlreadyRegistered(String),
41+
3642
#[error("Missing Payload:{0}")]
3743
MissingPayload(String),
3844

@@ -128,6 +134,8 @@ impl AppError {
128134
AppError::InvalidEmail(_) => ErrorCode::InvalidEmail,
129135
AppError::InvalidPassword(_) => ErrorCode::InvalidPassword,
130136
AppError::OAuthError(_) => ErrorCode::OAuthError,
137+
AppError::BadRequest(_) => ErrorCode::InvalidRequest,
138+
AppError::UserAlreadyRegistered(_) => ErrorCode::RecordAlreadyExists,
131139
AppError::MissingPayload(_) => ErrorCode::MissingPayload,
132140
AppError::DBError(_) => ErrorCode::DBError,
133141
AppError::OpenError(_) => ErrorCode::OpenError,
@@ -197,14 +205,16 @@ impl From<crate::gotrue::GoTrueError> for AppError {
197205
GoTrueError::Connect(msg) => AppError::Connect(msg),
198206
GoTrueError::RequestTimeout(msg) => AppError::RequestTimeout(msg),
199207
GoTrueError::InvalidRequest(msg) => AppError::InvalidRequest(msg),
200-
GoTrueError::ClientError(err) => AppError::OAuthError(err.to_string()),
208+
GoTrueError::ClientError(err) => AppError::BadRequest(err.to_string()),
201209
GoTrueError::Auth(err) => AppError::OAuthError(err),
202210
GoTrueError::Internal(err) => match (err.code, err.msg.as_str()) {
203-
(400, m) if m.starts_with("oauth error") => AppError::OAuthError(err.msg),
204-
(400, m) if m.starts_with("User already registered") => AppError::OAuthError(err.msg),
211+
(400, m) if m.starts_with("oauth error") => AppError::BadRequest(err.msg),
212+
(400, m) if m.starts_with("User already registered") => {
213+
AppError::UserAlreadyRegistered(err.msg)
214+
},
205215
(401, _) => AppError::OAuthError(err.msg),
206216
(422, _) => AppError::InvalidRequest(err.msg),
207-
_ => AppError::OAuthError(err.to_string()),
217+
_ => AppError::Internal(err.into()),
208218
},
209219
GoTrueError::Unhandled(err) => AppError::Internal(err),
210220
GoTrueError::NotLoggedIn(msg) => AppError::NotLoggedIn(msg),

libs/client-api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ url = "2.5.0"
3131
mime = "0.3.17"
3232
tokio-stream = { version = "0.1.14" }
3333
realtime-entity = { workspace = true }
34+
chrono = "0.4"
3435

3536
collab = { version = "0.1.0", optional = true }
3637
collab-entity = { version = "0.1.0" }

libs/client-api/src/http.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,10 +1116,7 @@ impl Client {
11161116
let expires_at = self.token_expires_at()?;
11171117

11181118
// Refresh token if it's about to expire
1119-
let time_now_sec = SystemTime::now()
1120-
.duration_since(SystemTime::UNIX_EPOCH)
1121-
.unwrap()
1122-
.as_secs() as i64;
1119+
let time_now_sec = chrono::Local::now().timestamp();
11231120
if time_now_sec + 10 > expires_at {
11241121
// Add 10 seconds buffer
11251122
self.refresh_token().await?;

0 commit comments

Comments
 (0)