Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
GraphQL response when access denied
in v7.2 GA2, I am exploring auth flow from a decoupled frontend app while also testing in the Altair Chrome extension
I have a GraphQL query:
query {
structuredContent(structuredContentId: 34612) {
title
}
}
If Liferay allows access based on Authorization header, I get back correctly the StructuredContent. However if I don't pass in a Authorization header at all, Liferay does not allow access and the following is returned with response code 200 OK:
{
"data": {
"structuredContent": null
},
"errors": [
{
"extensions": null,
"message": "Exception while fetching data (/structuredContent) : java.lang.SecurityException: Access denied to com.liferay.journal.service.JournalArticleService#getLatestArticle",
"path": null
}
]
}
I am rather new to GraphQL with auth and in the frontend app I want to choose to send the user to a login or display something useful if user is not authorized. Are there no error codes in the response ?
I have a GraphQL query:
query {
structuredContent(structuredContentId: 34612) {
title
}
}
If Liferay allows access based on Authorization header, I get back correctly the StructuredContent. However if I don't pass in a Authorization header at all, Liferay does not allow access and the following is returned with response code 200 OK:
{
"data": {
"structuredContent": null
},
"errors": [
{
"extensions": null,
"message": "Exception while fetching data (/structuredContent) : java.lang.SecurityException: Access denied to com.liferay.journal.service.JournalArticleService#getLatestArticle",
"path": null
}
]
}
I am rather new to GraphQL with auth and in the frontend app I want to choose to send the user to a login or display something useful if user is not authorized. Are there no error codes in the response ?
Mmm... GraphQL default behaviour is returning 200 and reading the errors block but it's true that it's hard to parse without an error code, I'll see if I can add it to the default error object.
I've been looking at what others do in the way of error codes in GraphQL responses, for example: https://www.apollographql.com/docs/apollo-server/data/errors/ ; I think this will take some planning
Whoa... I didn't know that there were well though solutions outside of the standard. Will take a look

Sounds good. Let me know if I can help.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™