Starts in:
1 DAY
21 HRS
51 MIN
35 SEC
Starts in:
1 D
21 H
51 M
35 S
Open Closed

Show 401 status with unauthorized error in API response #7897


User avatar
0
Sergei.Gorlovetsky created
  • ABP Framework version: v8.0
  • UI Type: Angularr
  • Database System: EF Core (SQL Server, Oracle, MySQL, PostgreSQL, etc..)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

I am creating API and using bearer token to authenticate the API requests.

I have used [Authorize] in my controller class and method. When I try to execute the API with the invalid token, in the logs I see the error message that says invalid token or token no longer valid.

But in the postman, I just see 401 unauthorized. However, I want to show a user-facing error message about an invalid token.


4 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    I have used [Authorize] in my controller class and method. When I try to execute the API with the invalid token, in the logs I see the error message that says invalid token or token no longer valid.

    What's the Angular-side error message? It should prompt unauthorized

  • User Avatar
    0
    Sergei.Gorlovetsky created

    I am not using UI for this one. My UI is just for tenant management. I am sharing API to be used by other integrations(outside of this project).

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    This is a normal response, 401 is a standard unauthorized return HTTP code, and you can handle it in UI.

    https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401

  • User Avatar
    0
    Sergei.Gorlovetsky created

    I understand 401 means unauthorized. I just wanted to show a Text-based response with 401. But I think it won't be possible then.

    You can close the ticket. Thanks

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06