Home > OS >  Google Cloud Functions - permission-denied vs failed-precondition
Google Cloud Functions - permission-denied vs failed-precondition

Time:11-30

Which HTTPs error type should I use when checking that the auth id is present?

const userId = context.auth.token.uid;

if (!userId) {
  throw new functions.https.HttpsError(
    "failed-precondition",
    "Authentication required."
  );
}

or

const userId = context.auth.token.uid;

if (!userId) {
  throw new functions.https.HttpsError(
    "permission-denied",
    "Authentication required."
  );
}

CodePudding user response:

Actually you can choose the error type you prefer among the list of available error types. As a matter of fact, this error code is going to be sent back to your front-end, which you normally control.

Now, looking at the list of error codes...

permission-denied: The caller does not have permission to execute the specified operation.

failed-precondition: Operation was rejected because the system is not in a state required for the operation's execution.

... I would choose permission-denied.

  • Related