-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: simplify error class without status code
- Loading branch information
1 parent
8c2f5ce
commit 0949850
Showing
2 changed files
with
8 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
export class AuthError extends Error { | ||
constructor( | ||
public status: number, | ||
public errorMessage: string | ||
) { | ||
super(errorMessage); | ||
this.name = 'AuthError'; | ||
} | ||
|
||
static INVALID_CREDENTIALS() { | ||
return new AuthError(403, 'Invalid username or password'); | ||
return new AuthError('Invalid username or password'); | ||
} | ||
|
||
static MISSING_CREDENTIALS() { | ||
return new AuthError(401, 'Missing username or password'); | ||
return new AuthError('Missing username or password'); | ||
} | ||
|
||
static TOKEN_CREATION_FAILED(username: string, domain: string) { | ||
return new AuthError(401, `Failed to obtain token for ${username} at ${domain}`); | ||
return new AuthError(`Failed to obtain token for ${username} at ${domain}`); | ||
} | ||
|
||
static MISSING_FACILITY(username: string) { | ||
return new AuthError(401, `User ${username} does not have a facility_id connected to their user doc`); | ||
return new AuthError(`User ${username} does not have a facility_id connected to their user doc`); | ||
} | ||
|
||
static INCOMPATIBLE_CHT_CORE_VERSION(domain: string, chtCoreVersion: string) { | ||
return new AuthError(401, `CHT Core Version must be 4.7.0 or higher. "${domain}" is running ${chtCoreVersion}.`); | ||
return new AuthError(`CHT Core Version must be 4.7.0 or higher. "${domain}" is running ${chtCoreVersion}.`); | ||
} | ||
|
||
static CANNOT_PARSE_CHT_VERSION(chtCoreVersion: string, domain: string) { | ||
return new AuthError(401, `Cannot parse cht core version ${chtCoreVersion} for instance "${domain}"`); | ||
return new AuthError(`Cannot parse cht core version ${chtCoreVersion} for instance "${domain}"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters