Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ErrorRequestSink.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, the Dart project authors.
3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14package org.dartlang.vm.service.internal;
15
16import com.google.gson.JsonObject;
17import org.dartlang.vm.service.logging.Logging;
18
19/**
20 * A {@link RequestSink} that reports with an error to each request.
21 */
23 /**
24 * The {@link ResponseSink} to send error responses to.
25 */
26 private final ResponseSink responseSink;
27
28 private final String code;
29 private final String message;
30
31 public ErrorRequestSink(ResponseSink responseSink, String code, String message) {
32 if (responseSink == null || code == null || message == null) {
33 throw new IllegalArgumentException("Unexpected null argument: " + responseSink + " "
34 + code + " " + message);
35 }
36 this.responseSink = responseSink;
37 this.code = code;
38 this.message = message;
39 }
40
41 @Override
42 public void add(JsonObject request) {
43 String id = request.getAsJsonPrimitive(ID).getAsString();
44 try {
45 // TODO(danrubel) is this the correct format for an error response?
46 JsonObject error = new JsonObject();
47 error.addProperty(CODE, code);
48 error.addProperty(MESSAGE, message);
49 JsonObject response = new JsonObject();
50 response.addProperty(ID, id);
51 response.add(ERROR, error);
52 responseSink.add(response);
53 } catch (Throwable e) {
54 Logging.getLogger().logError(e.getMessage(), e);
55 }
56 }
57
58 @Override
59 public void close() {
60 }
61}
ErrorRequestSink(ResponseSink responseSink, String code, String message)
const uint8_t uint32_t uint32_t GError ** error
Win32Message message