File tree Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -138,24 +138,23 @@ fn save_user_to_database(
138138) -> AppResult < User > {
139139 use diesel:: prelude:: * ;
140140
141- NewUser :: new (
141+ let new_user = NewUser :: new (
142142 user. id ,
143143 & user. login ,
144144 user. name . as_deref ( ) ,
145145 user. avatar_url . as_deref ( ) ,
146146 access_token,
147- )
148- . create_or_update ( user. email . as_deref ( ) , emails, conn)
149- . or_else ( |e| {
150- // If we're in read only mode, we can't update their details
151- // just look for an existing user
152- if is_read_only_error ( & e) {
153- find_user_by_gh_id ( conn, user. id ) ?. ok_or ( e)
154- } else {
155- Err ( e)
147+ ) ;
148+
149+ match new_user. create_or_update ( user. email . as_deref ( ) , emails, conn) {
150+ Ok ( user) => Ok ( user) ,
151+ Err ( error) if is_read_only_error ( & error) => {
152+ // If we're in read only mode, we can't update their details
153+ // just look for an existing user
154+ find_user_by_gh_id ( conn, user. id ) ?. ok_or_else ( || error. into ( ) )
156155 }
157- } )
158- . map_err ( Into :: into )
156+ Err ( error ) => Err ( error . into ( ) ) ,
157+ }
159158}
160159
161160fn find_user_by_gh_id ( conn : & mut impl Conn , gh_id : i32 ) -> QueryResult < Option < User > > {
You can’t perform that action at this time.
0 commit comments