Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
How to detect and handle firebase Permission Denied error code with swift

I am getting the following error while observe data from firebase realtime database. What I want to do is if the error is Permission Denied, I want to do a different action. How can I tell if the error is Permission Denied?

error :

Optional(Error Domain=com.firebase Code=1 "Permission Denied" UserInfo={NSLocalizedDescription=Permission Denied})

mycode:

func observeData(completion: @escaping (Bool) -> Void){
    Database.database().reference().child("values").observe(.value, with: { (snap) in
        completion(true)
    }){ (error) in
        let errorCode = (error as NSError).code
        if errorCode == .?????? {  //-->> what to come here
            self.anotherFunc()  //--> if Permission Denied call this func
            completion(false)
        }else{
            completion(true)
        }
    }
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This is what I did for Auth errors in my firebase app. Not sure if it will work in your context, but you might find it useful.

func firebaseErrorParser(error: Error) -> String? {
    if let errorCode = AuthErrorCode(rawValue: error._code) { // <- here!!

        switch errorCode { // switch case
        case .invalidVerificationCode:
            return "Wrong code or phone number!"
        default:
            return "An error occured... "
        }
    } else {
        return nil
    }
}

I only had one entry in my switch/case because the only error I wanted to give specific feedback to the user about was if the user entered the wrong phone number. It seems like you can do something similar with firestore permissions errors

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!