Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda