xref: /aosp_15_r20/external/cronet/net/websockets/websocket_errors.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/websockets/websocket_errors.h"
6 
7 
8 namespace net {
9 
WebSocketErrorToNetError(WebSocketError error)10 Error WebSocketErrorToNetError(WebSocketError error) {
11   switch (error) {
12     case kWebSocketNormalClosure:
13       return OK;
14 
15     case kWebSocketErrorGoingAway:  // TODO(ricea): More specific code?
16     case kWebSocketErrorProtocolError:
17     case kWebSocketErrorUnsupportedData:
18     case kWebSocketErrorInvalidFramePayloadData:
19     case kWebSocketErrorPolicyViolation:
20     case kWebSocketErrorMandatoryExtension:
21     case kWebSocketErrorInternalServerError:
22       return ERR_WS_PROTOCOL_ERROR;
23 
24     case kWebSocketErrorNoStatusReceived:
25     case kWebSocketErrorAbnormalClosure:
26       return ERR_CONNECTION_CLOSED;
27 
28     case kWebSocketErrorTlsHandshake:
29       // This error will probably be reported with more detail at a lower layer;
30       // this is the best we can do at this layer.
31       return ERR_SSL_PROTOCOL_ERROR;
32 
33     case kWebSocketErrorMessageTooBig:
34       return ERR_MSG_TOO_BIG;
35 
36     default:
37       return ERR_UNEXPECTED;
38   }
39 }
40 
41 }  // namespace net
42