[feature] More consistent API error handling (#637)

* update templates

* start reworking api error handling

* update template

* return AP status at web endpoint if negotiated

* start making api error handling much more consistent

* update account endpoints to new error handling

* use new api error handling in admin endpoints

* go fmt ./...

* use api error logic in app

* use generic error handling in auth

* don't export generic error handler

* don't defer clearing session

* user nicer error handling on oidc callback handler

* tidy up the sign in handler

* tidy up the token handler

* use nicer error handling in blocksget

* auth emojis endpoint

* fix up remaining api endpoints

* fix whoopsie during login flow

* regenerate swagger docs

* change http error logging to debug
This commit is contained in:
tobi
2022-06-08 20:38:03 +02:00
committed by GitHub
parent 91c0ed863a
commit 1ede54ddf6
130 changed files with 2154 additions and 1673 deletions

View File

@ -23,12 +23,13 @@ import (
"github.com/google/uuid"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
func (p *processor) AppCreate(ctx context.Context, authed *oauth.Auth, form *apimodel.ApplicationCreateRequest) (*apimodel.Application, error) {
func (p *processor) AppCreate(ctx context.Context, authed *oauth.Auth, form *apimodel.ApplicationCreateRequest) (*apimodel.Application, gtserror.WithCode) {
// set default 'read' for scopes if it's not set
var scopes string
if form.Scopes == "" {
@ -40,13 +41,13 @@ func (p *processor) AppCreate(ctx context.Context, authed *oauth.Auth, form *api
// generate new IDs for this application and its associated client
clientID, err := id.NewRandomULID()
if err != nil {
return nil, err
return nil, gtserror.NewErrorInternalError(err)
}
clientSecret := uuid.NewString()
appID, err := id.NewRandomULID()
if err != nil {
return nil, err
return nil, gtserror.NewErrorInternalError(err)
}
// generate the application to put in the database
@ -62,7 +63,7 @@ func (p *processor) AppCreate(ctx context.Context, authed *oauth.Auth, form *api
// chuck it in the db
if err := p.db.Put(ctx, app); err != nil {
return nil, err
return nil, gtserror.NewErrorInternalError(err)
}
// now we need to model an oauth client from the application that the oauth library can use
@ -70,17 +71,18 @@ func (p *processor) AppCreate(ctx context.Context, authed *oauth.Auth, form *api
ID: clientID,
Secret: clientSecret,
Domain: form.RedirectURIs,
UserID: "", // This client isn't yet associated with a specific user, it's just an app client right now
// This client isn't yet associated with a specific user, it's just an app client right now
UserID: "",
}
// chuck it in the db
if err := p.db.Put(ctx, oc); err != nil {
return nil, err
return nil, gtserror.NewErrorInternalError(err)
}
apiApp, err := p.tc.AppToAPIAppSensitive(ctx, app)
if err != nil {
return nil, err
return nil, gtserror.NewErrorInternalError(err)
}
return apiApp, nil