File tree Expand file tree Collapse file tree 5 files changed +57
-0
lines changed
Expand file tree Collapse file tree 5 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ When a request returns with an HTTP status code of `403`.
2929
3030When a request returns with an HTTP status code of ` 500 ` .
3131
32+ ## ` InvalidScopeError `
33+
34+ When a request returns with an HTTP status code of ` 400 ` and the response's body contains an error value of ` invalid_scope ` .
35+
3236## ` LoginRequiredError `
3337
3438Returned when a request that requires authentication is performed without the proper credentials.
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { AuthorizationRequiredError } from './authorization-required';
22import { BaseError } from './base' ;
33import { ForbiddenError } from './forbidden' ;
44import { InternalServerError } from './internal-server' ;
5+ import { InvalidScopeError } from './invalid-scope' ;
56import { NotFoundError } from './not-found' ;
67import { OTPRequiredError } from './otp-required' ;
78import { RateLimitError } from './rate-limit' ;
@@ -15,6 +16,7 @@ export {
1516 BaseError ,
1617 ForbiddenError ,
1718 InternalServerError ,
19+ InvalidScopeError ,
1820 NotFoundError ,
1921 OTPRequiredError ,
2022 RateLimitError ,
@@ -28,6 +30,7 @@ export default [
2830 AuthorizationRequiredError ,
2931 ForbiddenError ,
3032 InternalServerError ,
33+ InvalidScopeError ,
3134 NotFoundError ,
3235 OTPRequiredError ,
3336 RateLimitError ,
Original file line number Diff line number Diff line change 1+ import { BaseError } from './base' ;
2+
3+ export class InvalidScopeError extends BaseError {
4+ static hasError ( { body, status } = { } ) {
5+ if ( ! status || ( ! body || ! body . error ) ) {
6+ return false ;
7+ }
8+
9+ if ( status === 400 && body . error === 'invalid_scope' ) {
10+ return true ;
11+ }
12+
13+ return false ;
14+ }
15+
16+ constructor ( ) {
17+ super ( 'invalid_scope' , ...arguments ) ;
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ import { InvalidScopeError } from '../../../src/core' ;
2+
3+ describe ( 'InvalidScopeError' , ( ) => {
4+ describe ( 'hasError()' , ( ) => {
5+ it ( 'should return true if response status is 400 and error code is `invalid_scope`' , ( ) => {
6+ expect ( InvalidScopeError . hasError ( { body : { error : 'invalid_scope' } , status : 400 } ) ) . toBe ( true ) ;
7+ } ) ;
8+
9+ it ( 'should return false if response does not contain a `invalid_scope` code' , ( ) => {
10+ expect ( InvalidScopeError . hasError ( { body : { error : 'foo' } , status : 400 } ) ) . toBe ( false ) ;
11+ } ) ;
12+
13+ it ( 'should return false if response status is not 400' , ( ) => {
14+ expect ( InvalidScopeError . hasError ( { body : { error : 'invalid_scope' } , status : 401 } ) ) . toBe ( false ) ;
15+ } ) ;
16+ } ) ;
17+
18+ describe ( 'constructor()' , ( ) => {
19+ it ( 'should set `invalid_scope` message and given properties' , ( ) => {
20+ const error = new InvalidScopeError ( { foo : 'bar' } ) ;
21+
22+ expect ( error . foo ) . toBe ( 'bar' ) ;
23+ expect ( error . message ) . toBe ( 'invalid_scope' ) ;
24+ } ) ;
25+ } ) ;
26+ } ) ;
Original file line number Diff line number Diff line change 11import {
22 ForbiddenError ,
33 InternalServerError ,
4+ InvalidScopeError ,
45 NotFoundError ,
56 OTPRequiredError ,
67 RateLimitError ,
@@ -21,6 +22,10 @@ describe('ErrorFactory', () => {
2122 expect ( createError ( { status : 500 } ) ) . toBeInstanceOf ( InternalServerError ) ;
2223 } ) ;
2324
25+ it ( 'should create an `InvalidScopeError`' , ( ) => {
26+ expect ( createError ( { body : { error : 'invalid_scope' } , status : 400 } ) ) . toBeInstanceOf ( InvalidScopeError ) ;
27+ } ) ;
28+
2429 it ( 'should create a `NotFoundError`' , ( ) => {
2530 expect ( createError ( { status : 404 } ) ) . toBeInstanceOf ( NotFoundError ) ;
2631 } ) ;
You can’t perform that action at this time.
0 commit comments