-
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathinvalid-argument-error.js
More file actions
51 lines (45 loc) · 1.76 KB
/
Copy pathinvalid-argument-error.js
File metadata and controls
51 lines (45 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
/*
* Module dependencies.
*/
const OAuthError = require('./oauth-error');
/**
* Thrown when an argument to a function or constructor is missing or of the
* wrong type — i.e. a programming or configuration error in the code that
* integrates this library (for example, a missing server option, or a `model`
* that does not implement a required method).
*
* `InvalidArgumentError` is **not** an OAuth 2.0 protocol error: its
* `invalid_argument` code (HTTP 500) is not one of the error codes defined by
* RFC 6749 and must never be sent to an OAuth client. How it surfaces therefore
* depends on *when* it is raised:
*
* - **At construction / configuration time** (missing options, a `model` missing
* a required method, or `request`/`response` not being instances of this
* library's `Request`/`Response`) it is thrown to your code unchanged, before
* any response is produced — so you can catch it while wiring up the server.
* - **While handling a request** (for example, when a `model` returns malformed
* token data) the `token` and `authorize` handlers normalise it to a
* `ServerError` (`server_error`) before the response reaches the client,
* preserving the original error as `.inner`. So when you `catch` errors from
* `OAuth2Server#token` or `OAuth2Server#authorize`, expect a `ServerError`
* (inspect its `.inner`) for these cases — not an `InvalidArgumentError`.
*
* @class
*/
class InvalidArgumentError extends OAuthError {
/**
* @constructor
* @param message {string}
* @param properties {object=}
*/
constructor(message, properties) {
properties = {
code: 500,
name: 'invalid_argument',
...properties,
};
super(message, properties);
}
}
module.exports = InvalidArgumentError;