mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[oauth2orize] Typed errors (#35251)
See: -70608ed538/lib/errors/authorizationerror.js-70608ed538/lib/errors/oauth2error.js-70608ed538/lib/errors/tokenerror.js
This commit is contained in:
parent
32b5bf0bb7
commit
b60d757ef4
56
types/oauth2orize/index.d.ts
vendored
56
types/oauth2orize/index.d.ts
vendored
@ -58,6 +58,62 @@ export interface ErrorHandlerOptions {
|
||||
mode?: string;
|
||||
}
|
||||
|
||||
export class OAuth2Error extends Error {
|
||||
code: string;
|
||||
status: number;
|
||||
uri?: string;
|
||||
|
||||
/**
|
||||
* @param code Defaults to *server_error*.
|
||||
* @param status Defaults to 500.
|
||||
*/
|
||||
constructor(message?: string, code?: string, uri?: string, status?: number);
|
||||
}
|
||||
|
||||
export type AuthorizationErrorCode = 'invalid_request'
|
||||
| 'unauthorized_client'
|
||||
| 'access_denied'
|
||||
| 'unsupported_response_type'
|
||||
| 'invalid_scope'
|
||||
| 'temporarily_unavailable';
|
||||
|
||||
export class AuthorizationError extends OAuth2Error {
|
||||
/**
|
||||
* @param code The code sets the status unless status is present. Mapping:
|
||||
* invalid_request = 400
|
||||
* unauthorized_client = 403
|
||||
* access_denied = 403
|
||||
* unsupported_response_type = 501
|
||||
* invalid_scope = 400
|
||||
* temporarily_unavailable = 503
|
||||
* Defaults to *server_error*.
|
||||
* @param status Defaults to 500 if code is not specified.
|
||||
*/
|
||||
constructor(message?: string, code?: AuthorizationErrorCode | string, uri?: string, status?: number);
|
||||
}
|
||||
|
||||
export type TokenErrorCode = 'invalid_request'
|
||||
| 'invalid_client'
|
||||
| 'invalid_grant'
|
||||
| 'unauthorized_client'
|
||||
| 'unsupported_grant_type'
|
||||
| 'invalid_scope';
|
||||
|
||||
export class TokenError extends OAuth2Error {
|
||||
/**
|
||||
* @param code The code sets the status unless status is present. Mapping:
|
||||
* invalid_request = 400
|
||||
* invalid_client = 401
|
||||
* invalid_grant = 403
|
||||
* unauthorized_client = 403
|
||||
* unsupported_grant_type = 501
|
||||
* invalid_scope = 400
|
||||
* Defaults to server_error.
|
||||
* @param status Defaults to 500 if code is not specified.
|
||||
*/
|
||||
constructor(message?: string, code?: TokenErrorCode | string, uri?: string, status?: number);
|
||||
}
|
||||
|
||||
export type MiddlewareFunction = (req: MiddlewareRequest, res: ServerResponse, next: MiddlewareNextFunction) => void;
|
||||
|
||||
export type MiddlewareErrorFunction = (err: Error, req: MiddlewareRequest, res: ServerResponse, next: MiddlewareNextFunction) => void;
|
||||
|
||||
@ -91,3 +91,9 @@ server.deserializeClient((id, done) => {
|
||||
server.token();
|
||||
server.errorHandler();
|
||||
// );
|
||||
|
||||
// Test errors
|
||||
const tokenError = new oauth2orize.TokenError('Incorrect token', 'invalid_grant');
|
||||
const code: string = tokenError.code;
|
||||
new oauth2orize.AuthorizationError('Incorrect token', 'access_denied');
|
||||
new oauth2orize.OAuth2Error();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user