]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | ||
20 | package org.apache.thrift; | |
21 | ||
22 | import org.apache.thrift.protocol.TField; | |
23 | import org.apache.thrift.protocol.TProtocol; | |
24 | import org.apache.thrift.protocol.TProtocolUtil; | |
25 | import org.apache.thrift.protocol.TStruct; | |
26 | import org.apache.thrift.protocol.TType; | |
27 | ||
28 | /** | |
29 | * Application level exception | |
30 | */ | |
31 | class TApplicationException extends TException { | |
32 | ||
33 | private static var TAPPLICATION_EXCEPTION_STRUCT = { new TStruct("TApplicationException"); }; | |
34 | private static var MESSAGE_FIELD = { new TField("message", TType.STRING, 1); }; | |
35 | private static var TYPE_FIELD = { new TField("type", TType.I32, 2); }; | |
36 | ||
37 | // WARNING: These are subject to be extended in the future, so we can't use enums | |
38 | // with Haxe 3.1.3 because of https://github.com/HaxeFoundation/haxe/issues/3649 | |
39 | public static inline var UNKNOWN : Int = 0; | |
40 | public static inline var UNKNOWN_METHOD : Int = 1; | |
41 | public static inline var INVALID_MESSAGE_TYPE : Int = 2; | |
42 | public static inline var WRONG_METHOD_NAME : Int = 3; | |
43 | public static inline var BAD_SEQUENCE_ID : Int = 4; | |
44 | public static inline var MISSING_RESULT : Int = 5; | |
45 | public static inline var INTERNAL_ERROR : Int = 6; | |
46 | public static inline var PROTOCOL_ERROR : Int = 7; | |
47 | public static inline var INVALID_TRANSFORM : Int = 8; | |
48 | public static inline var INVALID_PROTOCOL : Int = 9; | |
49 | public static inline var UNSUPPORTED_CLIENT_TYPE : Int = 10; | |
50 | ||
51 | public function new(type : Int = UNKNOWN, message : String = "") { | |
52 | super(message, type); | |
53 | } | |
54 | ||
55 | public static function read(iprot:TProtocol) : TApplicationException { | |
56 | var field:TField; | |
57 | iprot.readStructBegin(); | |
58 | ||
59 | var message : String = null; | |
60 | var type : Int = UNKNOWN; | |
61 | ||
62 | while (true) { | |
63 | field = iprot.readFieldBegin(); | |
64 | if (field.type == TType.STOP) { | |
65 | break; | |
66 | } | |
67 | switch (field.id) { | |
68 | case 1: | |
69 | if (field.type == TType.STRING) { | |
70 | message = iprot.readString(); | |
71 | } | |
72 | else { | |
73 | TProtocolUtil.skip(iprot, field.type); | |
74 | } | |
75 | case 2: | |
76 | if (field.type == TType.I32) { | |
77 | type = iprot.readI32(); | |
78 | } | |
79 | else { | |
80 | TProtocolUtil.skip(iprot, field.type); | |
81 | } | |
82 | default: | |
83 | TProtocolUtil.skip(iprot, field.type); | |
84 | } | |
85 | iprot.readFieldEnd(); | |
86 | } | |
87 | iprot.readStructEnd(); | |
88 | return new TApplicationException(type, message); | |
89 | } | |
90 | ||
91 | public function write(oprot:TProtocol) : Void { | |
92 | oprot.writeStructBegin(TAPPLICATION_EXCEPTION_STRUCT); | |
93 | if (errorMsg != null) { | |
94 | oprot.writeFieldBegin(MESSAGE_FIELD); | |
95 | oprot.writeString(errorMsg); | |
96 | oprot.writeFieldEnd(); | |
97 | } | |
98 | oprot.writeFieldBegin(TYPE_FIELD); | |
99 | oprot.writeI32(errorID); | |
100 | oprot.writeFieldEnd(); | |
101 | oprot.writeFieldStop(); | |
102 | oprot.writeStructEnd(); | |
103 | } | |
104 | } |