-
-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathUsage.java
More file actions
67 lines (60 loc) · 1.89 KB
/
Usage.java
File metadata and controls
67 lines (60 loc) · 1.89 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby;
import java.lang.reflect.Executable;
import java.lang.reflect.Parameter;
import java.util.stream.Stream;
import io.jooby.exception.ProvisioningException;
/**
* Usage exceptions. They provide a descriptive message with a link for a detailed section.
*
* @since 2.1.0
*/
public class Usage extends RuntimeException {
/**
* Creates a new Usage exception.
*
* @param message Message.
* @param id Link to a detailed section.
*/
public Usage(String message, String id) {
this(
(message
+ "\nFor more details, please visit: "
+ System.getProperty("jooby.host", "https://jooby.io")
+ "/usage#"
+ id));
}
protected Usage(String message) {
super(message);
}
/**
* Occurs when trying to access a session which was not configured.
*
* @return No session present error mesage.
*/
public static Usage noSession() {
return new Usage("No session available. See https://jooby.io/#session-in-memory-session");
}
/**
* Thrown when the reflective bean converter has no access to a parameter name. Compilation must
* be done using <code>parameters</code> compiler option.
*
* @param parameter Parameter.
* @return Usage exception.
*/
public static Usage parameterNameNotPresent(Parameter parameter) {
Executable executable = parameter.getDeclaringExecutable();
int p = Stream.of(executable.getParameters()).toList().indexOf(parameter);
String message =
"Unable to provision parameter at position: '"
+ p
+ "', require by: "
+ ProvisioningException.toString(parameter.getDeclaringExecutable())
+ ". Parameter's name is missing";
return new Usage(message, "bean-converter-parameter-name-missing");
}
}